【cocoapods】でGoogleAnalyticsを導入 その1

前回cocoapodsをインストールした。
これを使ってxcodeのプロジェクトにGoogleAnalyticsのライブラリをインストールする。

ここを参照した。
iOS アプリにアナリティクスを追加する  |  iOS 向けアナリティクス  |  Google Developers

まず「ターミナル ウィンドウを開き、アプリの Xcode プロジェクトの場所に移動します。」と書いてあるが、ターミナル使ったことないとここでつまづきます。
ってゆーかツマヅイた。

なんとなーく、うろ覚えで、コマンドラインでディレクトリの移動ってなんか聞いたなと。
チェンジディレクトリでcdだったよーな。

って事で、ターミナルでcdと書いてスペースを開けて、プロジェクトのフォルダをドラッグアンドドロップしてみた。
そしてEnterを押すとうまく行ったようだ。

スクリーンショット 2016-04-20 18.18.27

cd ディレクトリ〜/フォルダ

スクリーンショット 2016-04-20 18.16.03

使いたいアプリのプロジェクトのディレクトリに移動したので続いて
「アプリの Podfile をまだ作成していない場合は、ここで作成します。」
とゆーこーとで、

$ pod init

とするとPodfileというファイルが作られた。
スクリーンショット 2016-04-20 18.21.23

開いてみると、

# 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 'admob' do

end

target 'admobTests' do

end

こんな感じですでに入力されている。

ここに下記の内容を追加。
pod ‘Google/Analytics’
場所はここで良いのかな?

# 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 'admob' do
pod 'Google/Analytics'
end

target 'admobTests' do

end

これで保存。

保存したらターミナルに戻って下記のコマンドを実行。

$ pod install

と、エラーが出た。

$ pod install
Updating local specs repositories

CocoaPods 1.0.0.beta.8 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
[!] Unable to satisfy the following requirements:

- `Google/Analytics` required by `Podfile`

Specs satisfying the `Google/Analytics` dependency were found, but they required a higher minimum deployment target.

[!] Unable to satisfy the following requirements:
で検索してみると

ダストボックスマイハウス: 【iOS】Podfileの設定とエラー

ふむふむ。iOSのバージョン指定がないと。

#のコメントアウトを外せばよいのかな?
とゆー事で、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 'admob' do
pod 'Google/Analytics'
end
 
target 'admobTests' do
 
end

と変更。

ターミナルに戻ってpod installを実行すると、

$ pod install
Updating local specs repositories

CocoaPods 1.0.0.beta.8 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 Google (2.0.4)
Installing GoogleAnalytics (3.14.0)
Installing GoogleInterchangeUtilities (1.2.0)
Installing GoogleNetworkingUtilities (1.2.0)
Installing GoogleSymbolUtilities (1.1.0)
Installing GoogleUtilities (1.3.0)
Generating Pods project
Integrating client project

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

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

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

と表示された。
プロジェクトファイルの有るディレクトリにも色々とファイルが入っててインストールは成功したようだ。

インストール後、開くのは「プロジェクト名.xcodeproj」ではなく「プロジェクト名.xcworkspace」のようだ。
気をつけないとね。

続く。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です