FireBaseを使ったAdMobの導入してみた(Cocoa pod使わない、かつObjective-C)

なにやら最近AdMobさんが「FireBase」なるものを使うことを推奨しているらしい。

それを使ってどうなるのかはさっぱりわからんが、何はともあれ入れてみました。

FireBaseを使えるAdMobのSDKを導入する流れ

基本的には[iPhone] アプリにAdMob広告を貼る(Firebase)に書いてあるとおり。

まずはAdMob + FireBaseのSDKをダウンロードする。

そして、すべてをプロジェクトに突っ込むのではなく、下記のファイルを突っ込む。

・GoogleMobileAds.framework
・FirebaseAnalytics.framework
・FirebaseInstanceID.framework
・GoogleInterchangeUtilities.framework
・GoogleSymbolUtilities.framework
・GoogleUtilities.framework
・Firebase.h
・module.modulemap

次に、AdMobで設定しているアプリとFireBaseをリンクする。これはAdMobのサイトで行う。リンクするとFireBaseのサイトで「GoogleService-Info.plist」をダウンロードできるようになるので、それをXcodeのプロジェクトに突っ込む。

今回はObjective-Cなので、さっき書いたリンク先に書いてあった「Build Settings」の「Swift Compiler – General」のくだりはいらない。
「Linking」「Other Linker Flags」に「-ObjC」を書くのはいらないのか不明。私のは以前から書いてたからそのまま。心配なら書いておけばOK。

んで、AppDelegate.mにプログラムを追加。

#import "Firebase.h"

そして、「application didFinishLaunchingWithOptions」に下記を追加。

[FIRApp configure];

あとは広告を表示するプログラムの.hが、FireBaseを使わないSDKは

#import 

だと思うけれど、これを下記に変更。

@import GoogleMobileAds;

他は今までどおりのSDKの広告表示のプログラムと同じ。これでAdMobを表示すること自体は完了。

なお、上記の「@import GoogleMobileAds;」でエラーが出る場合は、「Build Settings」の「Enable Modules(C and Objective-C)」をYESにすればエラーが消える。

しかし申請するとエラーが出る。というかメールが来る。

ただ、2016年10月現在、FireBaseの入ったAdMobのSDKだとプッシュ関連でitunes connectへアーカイブを送信すると、Appleから自動のエラーメールが届く。

This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSCalendarsUsageDescription key with a string value explaining to the user how the app uses this data.

This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSBluetoothPeripheralUsageDescription key with a string value explaining to the user how the app uses this data.

Missing Push Notification Entitlement – Your app includes an API for Apple’s Push Notification service, but the aps-environment entitlement is missing from the app’s signature. To resolve this, make sure your App ID is enabled for push notification in the Provisioning Portal. Then, sign your app with a distribution provisioning profile that includes the aps-environment entitlement. This will create the correct signature, and you can resubmit your app. See “Provisioning and Development” in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.

上記を簡単にいうと、「プッシュ通知するのに何も説明文がinfo.plistに書いてないぞ!」というのが2つか3つ。
そして、「プッシュ通知機能を使うのに、アプリが権限を持っていないぞ!」というのが1つ。

最初の2つの方の解決方法はこれ。
[AdMob] iOS 10用ビルドがはじかれる (7.11で修正されました)

具体的には、info.plistに下記3つを入れる。
Privacy – Calendars Usage Description
Advertisement would like to create a calendar event.

Privacy – Bluetooth Peripheral Usage Description
Advertisement would like to use bluetooth.

Privacy – Photo Library Usage Description
Advertisement would like to store a photo.

そしてプッシュ使うのに権限もってないぞって怒られるので(無視してリリースすることは可能だが)、それも下記の「Push Notifications」の権限を得ることで解決する。
iOSアプリをプッシュ通知に対応させる手順まとめ

APNsの証明証をダウンロードするのと、XcodeのCapabilitiesで「Push Notifications」のスイッチを入れるのを忘れずに。

とりあえずこれでエラーもなくFireBaseのAdMobを表示できたけれど、果たしてFireBaseを使うことにどれだけ意味があるのかしら。

  • このエントリーをはてなブックマークに追加

PICxPIC

会社を経営する30代男性。iPhoneアプリをつくったりしながら毎日ぴくぴく生きてます。

関連記事

  1. NO IMAGE
  2. NO IMAGE
  3. NO IMAGE
  4. NO IMAGE

プロフィール

PICxPIC
1983年生まれ。2010年からiOSアプリを開発し、2012年に法人化。メディア掲載やランキング、ダウンロード数などの詳しい実績などはこちら

PICxPICのアプリ

赤ちゃんの大冒険

おさるランド

動物オーケストラ2

子どもゲームランド

おしゃべりボタン

天空までのぼれ!

ジャンプで川下り

ひよこランド

動物オーケストラ

ポコポコアニマル

キラキラお絵かき

音が出るお絵かき

あいづちん