0
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.

FirebaseをiOSアプリに追加する

Last updated at Posted at 2023-10-17

実施前提

Podファイルを使った手順
Xcodeでxcworkspaceファイル(無い場合xcodeprojファイル)が開けること

・Github管理の場合
Githubからアプリをクローンして、ブランチ作成してチェックアウト

Firebase組み込み手順

公式↓にアクセスして「使ってみる」
https://firebase.google.com/?hl=ja

①「iOS」で設定開始

②「AppleアプリへのFirebaseの追加」

  • アプリの登録
  • バンドルID(Xcode Signing&CapablilitiesのBundleIdentifier)を登録

③ GoogleService-Info.plist をダウンロード
 ダウンロードしたGoogleService-Info.plistを以下の通り格納
 ・xcworkspaceファイル/xcodeprojファイルがある階層でディレクトリを作成(名前は任意)
 ・作成したディレクトリの配下にダウンロードしたGoogleService-Info.plistを格納
 ・TargetやSTG/PRDで識別できるよう名前を変更(ex: Staging-GoogleService-Info.plistなど)

④ Podファイルの編集
 ※無い場合はpod initで作成
 iOSバージョンはXcodeバージョンに従って設定(ex: platform :ios, '12.0')
 Podファイル各Targetに下記追記

pod 'Firebase/Analytics'
pod 'Firebase/Crashlytics'
pod 'Firebase/Performance'

⑤ Pod install
 ※xcworkspaceが無い場合、Pod installで作成される為、Xcodeをxcworkspaceで開き直す
 ※pod installのログに下記のような文が出る場合、次の手順の対象となるのでターミナルは閉じずにおくこと

[!]The `AppName [Release]` target overrides the `GCC_PREPROCESSOR_DEFINITIONS` build setting defined in `Pods/Target Support Files/Pods-AppName/Pods-AppName.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

⑥ Xcodeで各TargetのBuildSettingを開く
 下記に$(inherited)を追加
 ・Linking -> Other Linker Flags
 ・Framework Search Paths
 ・HEADER_SEARCH_PATH
 ・LIBRARY_SEARCH_PATH

⑦ User DeniedにPlistファイルの追加先を作成
 ③で設定したPlistファイルの名前をそれぞれ指定

⑧ XcodeでTargetのBuild Phaseを開く
 Editor>Add Build Phase>Add Run Script Build Phase
 Copy GoogleService-Info.plistを作成して、Shellに下記を追加

GOOGLE_SERVICE_INFO_PLIST_FROM="${PROJECT_DIR}/FirebaseConfiguration/${GOOGLE_SERVICE_INFO_PLIST_NAME}.plist"
BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
GOOGLE_SERVICE_INFO_PLIST_TO="${BUILD_APP_DIR}/GoogleService-Info.plist"
cp "${GOOGLE_SERVICE_INFO_PLIST_FROM}" "${GOOGLE_SERVICE_INFO_PLIST_TO}"

スクリーンショット 2023-09-05 15.29.52.png

⑨ BuildPhaseでdSYMファイルを自動的にアップロードするように設定する
 下記のステップ2の通り実行(dSYMアップロードのスクリプト名ex: Upload Crashlytics dSYMs files)
 
https://firebase.google.com/docs/crashlytics/get-started?platform=ios&authuser=0&hl=ja#set-up-dsym-uploading
 ※サイト内のスクリプトが変更されました→旧スクリプトでは${PODS_ROOT}/FirebaseCrashlytics/run
スクリーンショット 2023-09-05 15.34.55.png

⑩ 各TargetのProduct>Scheme>Edit Scheme>Run>Argumentsに下記を追加
 -FIRAnalyticsDebugEnabled
 -FIRDebugEnabled

11. UIApplicationDelegateに初期化コードを追加

12. Firebase Crashlyticsを開始する場合、下記のコードを追記してクラッシュするかテストする
https://firebase.google.com/docs/crashlytics/get-started?hl=ja&platform=ios#force-test-crash

手順11まででビルドが成功したら完了!
Firebaseで作成したプロジェクトのアクセス状況などを確認する。

0
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
0
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?