LoginSignup
1
1

More than 5 years have passed since last update.

Swift環境でFirebase Analyticsを設定してみる

Last updated at Posted at 2016-08-03

環境設定

前回のSwift環境でGoogle Analyticsを設定するを踏まえて、
今回はFirebase Analyticsを設定します。

基本的にはGoogleの公式ページを参考に。

CocoaPodsの設定

プロジェクトのPodfileにpod 'Firebase/Core'を追記します

$cd PJ名
$vi Podfile

Podfile.
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!

target 'PJ名' do
pod 'GoogleAnalytics'
pod 'Firebase/Core'
end

target 'PJ名Tests' do

end

target 'PJ名UITests' do

end

※記述はこんな感じ

$pod install

処理内容.
Updating local specs repositories

CocoaPods 1.1.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Analyzing dependencies
Downloading dependencies
Installing Firebase (3.4.0)
Installing FirebaseAnalytics (3.3.0)
Installing FirebaseInstanceID (1.0.8)
Using GoogleAnalytics (3.14.0)
Installing GoogleInterchangeUtilities (1.2.1)
Installing GoogleSymbolUtilities (1.1.1)
Installing GoogleUtilities (1.3.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 7 total
pods installed.

こんな感じになれば無事に完了。
Updating local specs repositories からなかなか進まないので、根気よく待ちましょう。3分ぐらいかかりました。。

プロジェクト側の設定

Appdelegate.swift
import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        // Firebaseの設定
        FIRApp.configure()


GoogleService-Info.plistの更新

Firebaseにログインして、アプリの管理からGoogleService-Info.plistをDLする。
DLしたGoogleService-Info.plistをプロジェクト側で上書いて更新する。
※これをやらないとアプリ起動時にエラーって落ちます。けっこうハマりました、、、

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