LoginSignup
4
5

More than 5 years have passed since last update.

AdMobのバナーを使う。

Posted at

CocoaPodsでビルドできなかったので手動でやる。

SDKのインストール

https://developers.google.com/mobile-ads-sdk/docs/ からSDKをダウンロード。

展開すると下記のようなディレクトリ構成となっている。

├── Add-ons
│   ├── DoubleClick
│   ├── Mediation
│   └── Search
├── GADAdMobExtras.h
├── GADAdNetworkExtras.h
├── GADAdSize.h
├── GADBannerView.h
├── GADBannerViewDelegate.h
├── GADInterstitial.h
├── GADInterstitialDelegate.h
├── GADRequest.h
├── GADRequestError.h
├── README.txt
└── libGoogleAdMobAds.a

これを次のような構成にしてvendor/GoogleAdMobSDKに入れる(Add-onsに入っているMediationを1つ上のディレクトリに入れた状態)

├── Mediation
├── GADAdMobExtras.h
├── GADAdNetworkExtras.h
├── GADAdSize.h
├── GADBannerView.h
├── GADBannerViewDelegate.h
├── GADInterstitial.h
├── GADInterstitialDelegate.h
├── GADRequest.h
├── GADRequestError.h
├── GoogleAdMobAdsSDK.bridgesupport
├── README.txt
└── libGoogleAdMobAds.a

設定

RakefileMotion::Project::App.setupのブロックに下記を追加。

Rakefile
  app.frameworks += ["OpenGLES", "OpenAL", "AVFoundation", "QuartzCore", "AudioToolbox", "MessageUI", "SystemConfiguration"]

  app.vendor_project('vendor/GoogleAdMobAdsSDK/', :static)

  app.libs << "/usr/lib/libz.dylib"
  app.libs << "/usr/lib/libxml2.2.dylib"

使用方法

viewDidLoadで下記のようにしてバナーを追加。

@banner = GADBannerView.alloc.initWithAdSize(KGADAdSizeBanner).tap do |b|
  # 自分のパブリッシャIDに変更する
  b.adUnitID = 'hogehogehoge'
  b.rootViewController = self
  b.frame = [[0, 0], [320, 50]]
  self.view.addSubview(b)
  b.loadRequest(GADRequest.request)
end

こんな感じで表示される。

スクリーンショット 2012-10-28 12.31.51.png (396×744)

参考

RobertLowe/Admob-Hpple-Example

こちらのサンプルから該当のAdMobの動作に必要な部分だけ抜き出した。

4
5
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
4
5