1
2

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 3 years have passed since last update.

firebaseを使って環境分けを設定する

Posted at

firebaseを利用した環境分けをする際、てこづったのでここにまとめておく。

※今回はrelease、debugの2つに分ける。
※podやfirebaseのセットアップについては省く

①まずfirebaseでアカウントを作り、プロジェクトを2つ作成する。(release用、debug用)

こんな感じでふたつ作る
スクリーンショット 2021-03-02 21.49.11.png

②両方のプロジェクトからGoogleService-Info.plistを取得する

③Xcodeのプロジェクトでフォルダをふたつ作り、分ける(debugのほうは名前を変える)

スクリーンショット 2021-03-01 22.13.02.png

④環境分けするためのファイルを追加する

FirebaseUtil.swift

import Foundation
import FirebaseCore

final class FirebaseUtil {

  static func setup() {
    #if DEBUG
    let name = "d_GoogleService-Info"
    #else
    let name = "GoogleService-Info"
    #endif
    let filePath = Bundle.main.path(forResource: name, ofType: "plist")
    if let options = FirebaseOptions(contentsOfFile: filePath!) {
      FirebaseApp.configure(options: options)
    } else {
      assertionFailure("Could'nt load config file")
    }
  }
}

⑤環境が分かれたか確認するクラッシュ用のViewControllerを追加する

CrashliticsViewController.swift
import UIKit

class CrashliticsViewController: UIViewController {

    
      @IBAction func tapCrash(_ sender: Any) {
        fatalError()
      }
    }

※Storyboard上のボタンと繋いで、タップするとクラッシュします。

⑥TARGETのEditSchemeを開き、releaseかdebugで分けるだけ

スクリーンショット 2021-03-02 21.42.33.png

⑦クラッシュの確認方法で少してこづったので、わかりやすい記事はこちら

⑧それぞれビルドし、クラッシュさせる

それぞれのプロジェクトのCrashlyticsを確認し、下記のように出ていたらOK
スクリーンショット 2021-03-02 21.52.35.png

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?