- 一:前提条件
- 将 SDK 添加到Xcode项目部分。
- 二:将插页式广告添加到项目中
- 对于GADInterstitial,建议您采用如下的生命周期设置:在应用启动时预加载它,并在它准备就绪后选择合适的时机在应用中展示它。以下代码段显示了如何创建GADInterstitial媒体资源、初始化该资源并随广告加载它。
- #import "GADInterstitial.h"
- @interface ViewController ()
- @property(nonatomic, strong) GADInterstitial *interstitial;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.interstitial = [[GADInterstitial alloc] init];
- self.interstitial.adUnitID = @"ca-app-pub-3940256099942544/4411468910";
- GADRequest *request = [GADRequest request];
- // Requests test ads on simulators.
- request.testDevices = @[ GAD_SIMULATOR_ID ];
- [self.interstitial loadRequest:request];
- }
- 当您可以展示插页式广告时,请在尝试展示之前查看它是否已准备就绪。以下是一个在游戏结束时展示插页式广告的示例。该应用必须在适当的时间显式调用此方法。
- - (void)gameOver {
- if ([self.interstitial isReady]) {
- [self.interstitial presentFromRootViewController:self];
- }
- // Rest of game over logic goes here.
- }
- KeyMob是最稳定最具效果的移动广告平台,致力于为广大开发者轻松实现安卓/IOS应用交叉推广,更方便对移动营销广告进行高效的优化管理,为开发者带来更高的广告收入。
来源: http://www.phpxs.com/code/1009611/