Question

our application shows interstitial iAds after each played level. At the moment a level finishes, we create the ad:

_interstitial = [[ADInterstitialAd alloc] init];
_interstitial.delegate = self;

and the delegate implements the following callback methods:

- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd
{
    [self finish];
}
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error
{
    [self finish];
}
- (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd
{
    [_interstitial presentFromViewController:self];
}
- (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd
{
    [self finish];
}

whereas the finish method cleans up things and forwards the user to the main menu. from the moment the ad object is created until the finish method is called, a spinning wheel is displayed on the screen.

Now the thing is that if no ad is loaded (for example if no internet connection is available) none of the callback functions ever gets called, so we also add a NSTimer when creating the Ad and check back after 10 seconds, like this:

_interstitial = [[ADInterstitialAd alloc] init];
_interstitial.delegate = self;
_timer = [NSTimer scheduledTimerWithTimeInterval:10
                                          target:self
                                        selector:@selector(checkForAds:)
                                        userInfo:nil
                                         repeats:false];

-(void)checkForAds:(NSTimer *)timer
{
    [_timer invalidate];
    if(!_interstitial.loaded)
        [self finish];
}

but this seems very unclean - and also it leads to a 10 seconds spinning wheel delay after each level if no internet connection is available for example (or if the connection is very bad).

so, my questions:

  1. what's the proper way to deal with this? I feel a timer here is not the right thing.

  2. I'm currently considering to create the Ad object before the level starts, and then after the level finishes immediately check the _interstitial.loaded property and show the ad in this case or skip over it otherwise, without using a timer. The problem is that a level session can take quite long (between 1 and 60 minutes I'd say) and I read that ads can expire, however there is no indication in the documentation how long it usually takes until ads expire and what happens in this case. Will the _interstitial.loaded property return false if the ad expired in the meantime in the background? is some callback function called when the ad expires? Is it a viable approach to create the ad object before a level starts (that is, 1-60 minutes before the ad actually gets displayed) and later just check if _interstitial.loaded is true and in this case display the ad?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top