我想在我的应用中添加一些广告,尤其是应用进入前景时的插页式广告。
我在AppDelegate.m中创建了这个方法:
- (void)splashInterstitial
{
UIImage *image;
if (TEST_IPHONE_5) {
image = [UIImage imageNamed:@"Default-568h.png"];
} else {
image = [UIImage imageNamed:@"Default.png"];
}
splashInterstitial_ = [[DFPInterstitial alloc] init];
splashInterstitial_.adUnitID = ADMOBS_OUVERTURE;
[splashInterstitial_ loadAndDisplayRequest:[GADRequest request]
usingWindow:self.window
initialImage:image];
}
我叫它两次:
- 在application:didFinishLaunchingWithOptions:
- 在applicationWillEnterForeground:
在application:didFinishLaunchingWithOptions:
中调用它时工作正常,但在第二种情况下,我有这个错误:
Google请求错误:无法完成Google广告请求 在超时发生之前。
显然,加载需要5秒钟,但我无法弄清楚如何强制我的应用程序等待它。
有谁知道怎么做?
感谢您的帮助。
答案 0 :(得分:1)
loadAndDisplayRequest:usingWindow:initialImage:
方法存在一些问题。 This blog post解释了如何使用GADInterstitial的loadRequest:
方法实现相同的目标。此实现更好,因为您可以更好地控制视图层次结构。
答案 1 :(得分:0)
我已经找到了如何在首次启动时使用插页式广告,但每次应用都处于活动状态时也是如此。
您只需在(void)splashInterstitial
中调用我的方法applicationDidBecomeActive:
。
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// ADMobs
[self splashInterstitial];
}
- (void)splashInterstitial
{
UIImage *image;
if (TEST_IPHONE_5) {
image = [UIImage imageNamed:@"Default-568h.png"];
} else {
image = [UIImage imageNamed:@"Default.png"];
}
splashInterstitial_ = [[DFPInterstitial alloc] init];
splashInterstitial_.adUnitID = ADMOBS_OUVERTURE;
[splashInterstitial_ loadAndDisplayRequest:[GADRequest request]
usingWindow:self.window
initialImage:image];
}