0

I would like to add some ads in my application, and especially an interstitial when the app enter foreground.

I've created this method in my 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];

}

I call it twice : - in application:didFinishLaunchingWithOptions: - in applicationWillEnterForeground:

It works fine when called in application:didFinishLaunchingWithOptions:, but in the second case, I have this error :

Google Request Error: The Google Ad request was unable to be fulfilled before a timeout occurred.

Obviously, it needs 5 seconds to load, but I can't figure out how to force my application to wait for it.

Does anyone knows how to do that ?

Thanks for your help.

Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42

2 Answers2

1

There are some issues with the loadAndDisplayRequest:usingWindow:initialImage: method. This blog post explains how you can achieve the same thing by using GADInterstitial's loadRequest: method. This implementation is better because you have more control over your view hierarchy.

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
0

I've found out how to have my interstitial on my first launch but also each time the app gets active.

You only have to call my method (void)splashInterstitial once, in 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];

}
Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42
  • i have tried this code in xcode 6.1.Admob Sdk is 6.12.2.i seen official Google admob Tutorial but there is no code in official site. – Maulik shah Nov 14 '14 at 12:50