【发布时间】:2015-02-09 17:00:43
【问题描述】:
我使用此代码添加插页式广告:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
nil];
gadinter = [[GADInterstitial alloc] init];
gadinter.delegate = self;
gadinter.adUnitID = @"ca-app-pub-8360827428091030/4165686904";
[gadinter loadRequest:request];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[gadinter presentFromRootViewController:self.window.rootViewController];
}
我得到了这个:
2015-02-09 18:57:12.636 iStrobe[5951:1824030] <Google> Cannot present interstitial. It is not ready.
2015-02-09 18:57:13.801 iStrobe[5951:1824030] <Google> No UIViewController supplied to the ad. Cannot continue.
知道为什么吗?在其他应用程序中它可以工作。
【问题讨论】:
-
你的 rootViewControlelr 是什么?是
UINavigationController,还是UITabBarController,还是UIViewController? -
你能在
[gadinter presentFromRootViewController:self.window.rootViewController]前面加一个NSLog(%"%@", self.window.rootViewController),看看值是多少?会不会是nil? -
我正在浏览documentation。似乎他们将广告初始化代码放在
viewDidLoad中。当这个- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial被调用时,你的 rootViewController 可能还没有准备好。 -
感谢@YuchenZhong,我在viewDidLoad中添加了,现在可以了。
-
那太好了,如果您弄清楚了,您可以自己写答案,以便将来对其他人有所帮助..
标签: ios objective-c interstitial