mzgkworks

iOSを中心にプログラミング関係について書く

【Firebase】iOSアプリにFirebaseを導入してアクセス解析

iOSアプリにGoogleのFirebaseを導入して、アクセス解析(Analytics)を行う。
導入はGoogleアカウントを作成し、cocoaPodsでインストールする程度の手軽さ。

環境

  • Xcode 7.3.3
  • cocoaPods 1.0.1
  • Firebase 3.3.0

ログイン

プロジェクトの作成

導入したいアプリ用にプロジェクトを作成する。
プロジェクト名 : アプリ名に合わせた
地域 : 日本に変更
f:id:mzgkworks:20160726151331p:plain

iOSアプリへの導入

プロジェクト作成後のページで、iOSアプリに追加をクリック。

f:id:mzgkworks:20160726151808p:plain

アプリのBundle ID, App Store ID(省略可)を入力。

f:id:mzgkworks:20160726152306p:plain

GoogleService-Info.plistをプロジェクトに追加

「GoogleService-Info.plist」がダウンロードされるので、Xcodeでプロジェクトに追加する。 f:id:mzgkworks:20160726152735p:plain

SDKの導入(cocoaPods)

Terminal.appを起動し、cocoaPods経由でライブラリを導入する。
Analyticsのみを使用する場合は、pod 'Firebase/Core'を記述する。
f:id:mzgkworks:20160726153505p:plain

$ pod install

$ pod install
Analyzing dependencies
Downloading dependencies
Installing Firebase (3.3.0)
Installing FirebaseAnalytics (3.2.1)
Installing FirebaseInstanceID (1.0.7)
Installing GoogleInterchangeUtilities (1.2.1)
Installing GoogleSymbolUtilities (1.1.1)
Installing GoogleUtilities (1.3.1)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `xxxx.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 6 total pods installed.

AppDelegate.swift

  • Firebaseのインポート
  • Firebaseの呼び出し f:id:mzgkworks:20160726154025p:plain

以上