Handling empty ADBannerView (iOS, Unity 4.5.1 Free)

I’ve added an ADBannerView to my game following the code in the Unity docs (http://docs.unity3d.com/ScriptReference/ADBannerView.html), and I’ve been testing it thorougly to make sure it won’t show empty banners (Apple seems to be very strict when it comes to reviewing games with Ads, and reject those that show empty banners).

Most of the time, the banner behaves as expected: it shows when an ad is loaded and hides when “iAd library is not available”. But, from time to time (unfortunately not when I’m debugging from Xcode, but when I’m playing the game far from my computer), the deadly empty banner appears. I do not know how to reproduce this error, it just happens sometimes.

I’ve been looking for a way to handle this, but I cannot find a property, event or delegate in the ADBannerView class to do so.

This is what I’m doing: I created an iAdManager class which creates and shows the banner, and I call this class in my Main Menu scene like this:

public class MainMenuController : MonoBehaviour {
        // some code...
        private iAdManager adManager;

	void Awake(){
		// some code

		adManager = new iAdManager();
		adManager.ShowBanner();
	} 

        // more code
}

And the code for the AdManager class is this:

public class iAdManager {
#if UNITY_IOS
	private ADBannerView banner = null;

	public iAdManager(){
		ADBannerView.onBannerWasClicked += onAdClicked;
		ADBannerView.onBannerWasLoaded += onAdLoaded;
	}
#endif

	public void ShowBanner(){
#if UNITY_IOS
		if(ADBannerView.IsAvailable (ADBannerView.Type.Banner)){
			Debug.Log(this.ToString () + ": App running in iOS, preparing banner.");
			banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Bottom);
		} else {
			Debug.Log(this.ToString () + "." + ADBannerView.Type.Banner.ToString () + ": is not available.");
		}
#else
		Debug.Log(this.ToString () + ": App not running in iOS, banner will not show at all.");
#endif
	}

	private void onAdClicked(){
		Debug.Log(this.ToString () + ": Banner was clicked!");
	}
	
	private void onAdLoaded(){
		Debug.Log(this.ToString () + ": Banner is loaded!");
#if UNITY_IOS
		banner.visible = true;
		if(banner.visible && !banner.loaded) banner.visible = false;
#endif
	}
}

As you can see, I’m trying to handle errors with a “if(banner.visible && !banner.loaded) banner.visible = false;” but this doesn’t seem to work all the time.

Any ideas?

The issue is being worked on. Please see http://forum.unity3d.com/threads/adbanner-omission-on-ios.336929/ for progress.