1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cloud Functionsでステージング環境作成〜Xcodeでターゲットを分けるまで

Last updated at Posted at 2024-02-23

はじめに

Firebaseでステージング環境を作成し、 Xcodeでターゲットを分ける作業をしたので、
手順をまとめてみました。

前提条件

  • Firebase上にStaging環境を既に作っている
  • Firebase CLIを既にインストールしている

環境

  • Xcode15
  • Firebase CLI 13.0.2

Cloud Functionsをステージングにデプロイする。

どのプロジェクトか選択する

firebase use --add
Which project do you want to add? (Use arrow keys)
> sampleProject

エイリアス名をつける

What alias do you want to use for this project?
staging

これで環境ができるのでステージングを選択

firebase use staging
ow using alias staging (プロジェクト名)

デプロイ

firebase deploy --only functions

ローカルでエミュレート

firebase emulators:start

GoogleServiceInfo.plistの取り込み

下記のフォルダ構成でGoogleServiceInfo.plistを取り込みます。
スクリーンショット 2024-02-23 12.17.36.png

 該当するTargetだけにチェックを入れる
スクリーンショット 2024-02-23 12.20.21.png

AppdelegateでFirebaseApp初期化

import FirebaseCore
...
FirebaseApp.configure()

↓Firebaseはここまでで問題ないので以下はその他の目的でTargetを分けたい人向け

Xcodeでターゲットを分ける

ターゲット複製

ターゲットを複製してターゲット名をStaging SampleTarget変更
スクリーンショット 2024-02-15 19.32.27.png

不要なinfo.plist削除

今回は同じinfo.plistを使いたい為複製で出来た不要なSampleTarget copy-info.plistを削除
スクリーンショット 2024-02-16 12.49.54.png

同じinfo.plistを読むようにステージングターゲットのGeneral->Packaging->info.plist FileをSampleTarget/Info.plistに変更
スクリーンショット 2024-02-23 10.11.24.png

スキームの設定変更

manage SchemesをクリックしてSampleTarget-Stagingにターゲットと一緒に名前を合わせる
スクリーンショット 2024-02-23 10.55.26.png

Preprocessor Macrosの設定

今回GoogleInfo.plistはファイル名同じなので必要ありませんが、その他で必要であればPreprocessor Macrosの設定をします。
Preprocessor Macrosの設定でStagingからRELEASEを削除してステージングを追加
スクリーンショット 2024-02-23 10.40.27.png

Preprocessor Macrosの確認

下記のコードで確認

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
#if STAGING
    print("STAGINGです")
#else
    print("それ以外です")
#endif
    }
}

スクリーンショット 2024-02-23 11.10.43.png

終わり!!

参考:
https://zenn.dev/oimo_revolution/articles/17ab026cbef464

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?