Christian Kreiter
Christian Kreiter

Reputation: 620

Why does my Interstitial iAd crash when there is no Internet connection?

I can't figure out how to restrict my Interstitial iAd to only show when there is an internet connection. I have implemented the -bannerView:didFailToReceiveAdWithError: function and tried logging the error, but it never even gets called.

The result of my app trying to load an iAd without an Internet connection is a nasty memory issue, and a sudden crash.

I'm sure the solution is simple, but I can't find it anywhere else.

Upvotes: 0

Views: 68

Answers (1)

Daniel Storm
Daniel Storm

Reputation: 18898

It sounds like you're requesting an interstitial ad when an interstitial fails to load, resulting in an infinite loop of ad requests when there is no internet connection.

Here's a simple function to check for connectivity:

-(BOOL)canConnectToGoogle {
    NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://google.com"] encoding:NSUTF8StringEncoding error:nil];
    return ( URLString != NULL ) ? YES : NO;
}

Upvotes: 0

Related Questions