【Swift】iOSアプリにgoogle AdMob 広告を載せる

iOSアプリにgoogle AdMob 広告を載せる。

Firebase Consoleでプロジェクト作成

プロジェクトを作り、「GoogleService-Info.plist」をダウンロードし、プロジェクト内に追加する。

使ってみる  |  Firebase

CocoaPodsの設定

$ sudo gem install cocoapods

cd [.xcodeprojがある dir]

$ pod init

Podfile が生成される

↓Podfileを書き換える

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TestAdMobBannerFireBase' do
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/AdMob'
end

↓ターミナルコマンド

$ pod install

(この後、少し時間がかかる)

「 .xcworkspace 」ができるので、以降は、こちらから起動する。

Xcode

import GoogleMobileAds
,GADBannerViewDelegate
let AdMobID = "ca-app-pub-・・・"
let TEST_ID = "ca-app-pub-・・・"
let AdMobTest:Bool = false
@IBOutlet weak var bannerView: GADBannerView!
print("Google Mobile Ads SDK version: \(GADRequest.sdkVersion())")
if AdMobTest {
bannerView.adUnitID = TEST_ID
}
else{
bannerView.adUnitID = AdMobID
}
bannerView.rootViewController = self
bannerView.load(GADRequest())

返信を残す

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

CAPTCHA