![](https://ios-pro.com/wp-content/uploads/2024/05/0a9ea81349516cb3091bc4a82fd4c0ee-150x150.png)
5日目は、
Google AdMobの実装・手続き
について解説します。
![](https://ios-pro.com/wp-content/uploads/2024/05/0a9ea81349516cb3091bc4a82fd4c0ee-150x150.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/0a9ea81349516cb3091bc4a82fd4c0ee-150x150.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/0a9ea81349516cb3091bc4a82fd4c0ee-150x150.png)
App Storeに公開するとき、
並行して実施した
AdMob関連の手続きをまとめました。
前回、4日目に解説した、アップロード、リジェクト対応などの手続きは以下のページから確認ください。
![](https://ios-pro.com/wp-content/uploads/2024/05/bd761dd6547d9feab16738009e4628df.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/bd761dd6547d9feab16738009e4628df.png)
次回、6日目に解説する、プライバシーポリシー、トラブル対応などの手続きは以下のページから確認ください。
![](https://ios-pro.com/wp-content/uploads/2024/05/015e28593b7ad0ee5d48773f586f4c82.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/015e28593b7ad0ee5d48773f586f4c82.png)
1. Google AdMobにアプリの登録
Google AdMobアカウントが作成済みとして解説します。
アプリで広告収入を得るためGoogle AdMobを登録します。
![](https://ios-pro.com/wp-content/uploads/2024/05/cdc90a4b099fb075c7e289f8dc17fd4d.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/cdc90a4b099fb075c7e289f8dc17fd4d.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/44618b8049d1d1f04f9379a99dac7f63-1024x306.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/44618b8049d1d1f04f9379a99dac7f63-1024x306.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/95d1a8c7e48fb4f21d2a037ab0748340-1024x210.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/95d1a8c7e48fb4f21d2a037ab0748340-1024x210.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/52be2b282dde1fd55a61794f0c08156b-1024x270.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/52be2b282dde1fd55a61794f0c08156b-1024x270.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/ba89a501e5c6774230e04c4272353322-1024x396.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/ba89a501e5c6774230e04c4272353322-1024x396.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/cad7591e4e39edbbe64290fcfe74b2e1-1024x368.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/cad7591e4e39edbbe64290fcfe74b2e1-1024x368.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/a9e18627ae0c674226e8ccf7f8da3bdb-1024x436.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/a9e18627ae0c674226e8ccf7f8da3bdb-1024x436.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/2959386fe7ff73c9834ef6e3ebed9dfa-wpp1714562427491-1024x510.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/2959386fe7ff73c9834ef6e3ebed9dfa-wpp1714562427491-1024x510.png)
以下のように広告ユニットIDを登録して、テストIDと本番ID(上記ID)をすぐに切り替えられるようにしておく。
![](https://ios-pro.com/wp-content/uploads/2024/05/20e88b5fb9e6ef72c1cab7c4cbd5df00-wpp1714563126315-1024x286.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/20e88b5fb9e6ef72c1cab7c4cbd5df00-wpp1714563126315-1024x286.png)
「Google Mobile Ads SDK ガイド」をクリック
2. Google Mobile Ads SDK のアプリへの統合
ここでは、AdMob で iOS アプリを収益化したいが Firebase を使用していない場合について解説します。
![](https://www.gstatic.com/devrel-devsite/prod/v1698cdd3153b47734bb6d9d8688c4490898207543be76b2c5805f109c27c7695/developers/images/opengraph/white.png)
![](https://www.gstatic.com/devrel-devsite/prod/v1698cdd3153b47734bb6d9d8688c4490898207543be76b2c5805f109c27c7695/developers/images/opengraph/white.png)
以下のコードを入力し、エンター。パスワードを聞かれるので入力。
![](https://ios-pro.com/wp-content/uploads/2024/05/65dacbf26b2bcaab4ec8174cb50866e9-1-1024x120.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/65dacbf26b2bcaab4ec8174cb50866e9-1-1024x120.png)
以下のように、表示されれば、インストール終了。
![](https://ios-pro.com/wp-content/uploads/2024/05/2188c99cea351e42c9e249c58e909f20-1024x399.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/2188c99cea351e42c9e249c58e909f20-1024x399.png)
以下のコードを入力し、Enterキー。
![](https://ios-pro.com/wp-content/uploads/2024/05/e7bd5b3fce856b73612bf1497528ddf3-1024x60.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/e7bd5b3fce856b73612bf1497528ddf3-1024x60.png)
以下のようになれば、セットアップ完了。
![](https://ios-pro.com/wp-content/uploads/2024/05/44e3e3a7ae3d119e21452667f4155606-1024x111.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/44e3e3a7ae3d119e21452667f4155606-1024x111.png)
同じ名前が2つありますが、外側の階層を選択。
![](https://ios-pro.com/wp-content/uploads/2024/05/ddd8d18954d0162684d3144b132ccc1b-1024x121.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/ddd8d18954d0162684d3144b132ccc1b-1024x121.png)
以下のコードを入力し、Enterキー。
![](https://ios-pro.com/wp-content/uploads/2024/05/07892e050c7c446b052d5bcd51b5b69b-1024x87.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/07892e050c7c446b052d5bcd51b5b69b-1024x87.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/1735617019f6e746832266a02e2d7c10.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/1735617019f6e746832266a02e2d7c10.png)
次の行を追記し、保存(コマンド+S)。
![](https://ios-pro.com/wp-content/uploads/2024/05/9c5b6cbb1b29161ed0adee90fa9eef2f-1024x343.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/9c5b6cbb1b29161ed0adee90fa9eef2f-1024x343.png)
以下のコードを入力し、エンター。
![](https://ios-pro.com/wp-content/uploads/2024/05/aab5b0a428769fc821dadda01a110230-1024x87.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/aab5b0a428769fc821dadda01a110230-1024x87.png)
以下の黄色のエラーが出る。
![](https://ios-pro.com/wp-content/uploads/2024/05/c92a3a9d90cbc5bca7c9f767f3116dbb-1024x439.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/c92a3a9d90cbc5bca7c9f767f3116dbb-1024x439.png)
以下のように、Podfileを修正し、再度「pod install」すると、今度はエラーが出ませんでした。
![](https://ios-pro.com/wp-content/uploads/2024/05/da7ca4199a16f6431637993475b7fa06.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/da7ca4199a16f6431637993475b7fa06.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/970142586b5ba28324f079eab4be1c4d-1024x292.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/970142586b5ba28324f079eab4be1c4d-1024x292.png)
3. Info.plist を更新する
一旦、Xcodeを終了し、以下の白いプロジェクトを開く。(開くまでに少し時間かかる)
![](https://ios-pro.com/wp-content/uploads/2024/05/0edfbb70586fd6ec62fa2cfd4ee7a2c5.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/0edfbb70586fd6ec62fa2cfd4ee7a2c5.png)
「TARGETS」の「Info」タブを選択し、プラスボタンを押す。
![](https://ios-pro.com/wp-content/uploads/2024/05/cbfe244b7b61835c9ccf2531be051ac1-1024x407.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/cbfe244b7b61835c9ccf2531be051ac1-1024x407.png)
KEY、Value(広告アプリID)を登録
- Key:GADApplicationIdentifier
- Value:広告アプリID(STEP8の上のID)
![](https://ios-pro.com/wp-content/uploads/2024/05/7e0b04a3e0ac692a6b83e9ab23fffa10.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/7e0b04a3e0ac692a6b83e9ab23fffa10.png)
さらにプラスボタンを押し、KEY、Valueを登録
- Key:GADIsAdManagerApp
- Value:true
続いて、「Info.plist」右クリック、「Open As」、「Source Code」をクリック
![](https://ios-pro.com/wp-content/uploads/2024/05/a33c0d278c79279c35b7fdf9cfef83e6.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/a33c0d278c79279c35b7fdf9cfef83e6.png)
「Google Mobile Ads SDK ガイド」の以下の内容をコピー。
コピーボタン「赤枠」ですべてコピー後、登録済み「青枠」を削除する。
![](https://ios-pro.com/wp-content/uploads/2024/05/00f4a4d0aaba6609d9904a89650d7671-1.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/00f4a4d0aaba6609d9904a89650d7671-1.png)
コマンド+Bを実行すると、以下のエラー。
Sandbox: bash(10648) deny(1) file-write-create /Users/Hiro/iOS-Pro/App/WalDiary/Pods/resources-to-copy-WalDiary.txt
「TARGETS」、「Build Settings」、「All」を選択後、検索窓で「Sandbox」を検索
「User Script Sandboxing」を「Yes」から「No」に変更
![](https://ios-pro.com/wp-content/uploads/2024/05/365346df2f31a06457283ec3b16dc30c.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/365346df2f31a06457283ec3b16dc30c.png)
再度、コマンド+Bを実行すると、エラーはなくなりました。
4. 広告表示のテスト
下記のバナー用のコードを作成し、ContentViewで呼び出すようにした。
import Foundation
import SwiftUI
import GoogleMobileAds
struct AdBanner: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let bannerView = GADBannerView(adSize: GADAdSizeBanner)
let viewController = UIViewController()
bannerView.adUnitID = K.adUnitID //バナー広告
bannerView.rootViewController = viewController
bannerView.load(GADRequest())
viewController.view.addSubview(bannerView)
bannerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
bannerView.centerXAnchor.constraint(equalTo: viewController.view.safeAreaLayoutGuide.centerXAnchor),
bannerView.bottomAnchor.constraint(equalTo: viewController.view.safeAreaLayoutGuide.bottomAnchor)
])
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
import GoogleMobileAds
struct ContentView: View {
var body: some View {
ZStack {
}
AdBanner().frame(height: 50)
}
}
画面下部に、バーナー広告の表示を確認。
![](https://ios-pro.com/wp-content/uploads/2024/05/df23ecae5e2505c9d63554731aaf4e72-473x1024.jpeg)
![](https://ios-pro.com/wp-content/uploads/2024/05/df23ecae5e2505c9d63554731aaf4e72-473x1024.jpeg)
5. (アプリ公開後)AppStoreの追加
アプリ公開後、広告とアプリの結びつけが必要です。これをしないと広告収入が発生しません。
ストアを追加をクリック
![](https://ios-pro.com/wp-content/uploads/2024/05/8098ca1efc2e4624821345f2f8e3b361-1024x454.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/8098ca1efc2e4624821345f2f8e3b361-1024x454.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/0e9c54d610dae5abe6288eeb4967efd1-1024x444.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/0e9c54d610dae5abe6288eeb4967efd1-1024x444.png)
リリースしたアプリが表示されたら、「追加」をクリック
![](https://ios-pro.com/wp-content/uploads/2024/05/209535249211943e1011376959cbd9a7-1024x556.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/209535249211943e1011376959cbd9a7-1024x556.png)
保存ボタンをクリック
![](https://ios-pro.com/wp-content/uploads/2024/05/49dcda92f3947964021cee1dbf177fb5-1024x396.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/49dcda92f3947964021cee1dbf177fb5-1024x396.png)
完了をクリック
![](https://ios-pro.com/wp-content/uploads/2024/05/b00e9220367e299253531f75a2efeca1-1024x477.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/b00e9220367e299253531f75a2efeca1-1024x477.png)
ステータスが「審査中」
![](https://ios-pro.com/wp-content/uploads/2024/05/a2bc7ddaeb3bd9486841e8742400ecdb-1024x576.png)
![](https://ios-pro.com/wp-content/uploads/2024/05/a2bc7ddaeb3bd9486841e8742400ecdb-1024x576.png)
コメント