0

我想在我的应用程序中添加一些广告,尤其是当应用程序进入前台时的插页式广告。

我在 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];

}

我叫了两次:-in application:didFinishLaunchingWithOptions: -inapplicationWillEnterForeground:

调用时它工作正常application:didFinishLaunchingWithOptions:,但在第二种情况下,我有这个错误:

Google 请求错误:在发生超时之前无法满足 Google 广告请求。

显然,加载需要 5 秒,但我不知道如何强制我的应用程序等待它。

有谁知道该怎么做?

谢谢你的帮助。

4

2 回答 2

1

该方法存在一些问题loadAndDisplayRequest:usingWindow:initialImage:这篇博文解释了如何使用 GADInterstitial 的loadRequest:方法来实现相同的目标。这种实现更好,因为您可以更好地控制视图层次结构。

于 2013-06-28T23:08:29.370 回答
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];

}
于 2013-07-01T11:08:38.557 回答