So, Unity provides a nice and easy to use wrapper for iOS banner ads. This is great and I use it in my ad mediator code (I don’t trust 3rd party mediators… had issues with them all). Unfortunately, in their wisdom, they left out one little thing… there is no call back when a iAd doesn’t load, so you get a lovely blank ad space – earning you slightly less money than an actual iAd would.
-(void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error { ::printf_console("ADBannerView error: %s\n", [[error localizedDescription] UTF8String]); _showingBanner = NO; [self layoutBannerImpl]; }
That’s the code they have in iAD.mm when you build an iOS project.
With the simple addition of one line you can get a notification that the ad failed to load and then present another ad from another provider.
-(void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error { ::printf_console("ADBannerView error: %s\n", [[error localizedDescription] UTF8String]); _showingBanner = NO; UnityADBannerViewWasLoaded(); // Added by CG [self layoutBannerImpl]; }
As you can see, I just fire the existing notification system they already have. The triggered callback just checks to see if _showingBanner is set to ‘NO’ and if it is, then it signifies that no ad was loaded – simple right?
Unfortunately, I have to update this line every time I ‘Replace’ or build a new iOS App – you wouldn’t believe the number of times I’ve forgotten… or maybe you would.
Pretty simple for the folks at Unity to include this in their iOS project template, and they’ve been asked to do so by many different developers, but nothing yet.