Hi,
I am trying to get my iAd code (which is working perfectly), to fall back to AdMob (using Prime31’s plugin) when there are no ads being served from Apple.
Here’s the code I am using:
#pragma strict
import System.Collections.Generic;
// Bard iAd
var banner:ADBannerView;
function Start () {
// Bard iAd + AdMob + Chartboost
StartCoroutine(ShowBanner());
ChartBoostBinding.showInterstitial( "default" );
AdMobBinding.init( "a1518d4a265caae", true );
}
function Update () {
}
function Awake () {
ChartBoostBinding.cacheInterstitial( "default" );
}
function ShowAdsChartboost () {
ChartBoostBinding.showInterstitial( "default" );
}
// Bard iAd
function ShowBanner() {
banner = new ADBannerView();
banner.autoSize = true;
banner.autoPosition = ADPosition.Bottom;
Debug.Log(banner.error);
while (!banner.loaded banner.error == null)
yield;
if (banner.error == null)
banner.Show();
else banner = null;
}
I tried changing the "if (banner.error == null) to this:
if(banner.error == false) {
banner.Show();
} else if(banner.error == true) {
AdMobBinding.createBanner( AdMobBannerType.iPhone_320x50, AdMobAdPosition.BottomRight );
}
Which compiled, but then I got no ads whatsoever.
Has anyone done this and have some tips on how to get it working?
Did you end up finding a solution? I’m sitting on the same problem with my code at the moment.
Thanks.
I don’t know about the prime31 plug-in but the code above looks just like this code: http://docs.unity3d.com/Documentation/ScriptReference/ADBannerView.html
Given that, the way this is designed, it will only return from the coroutine until both conditions are met in the “while” meaning that:
- there is NO banner.error
- banner.loaded IS true
What you need to trigger off is the “banner.loaded” so the entire method would need to be re-written and not shoe-horned in.
In addition, the .error is not a boolean, it is either an actual result OR null so the example shown would never be true because banner.error will never be equal to “false”.
Sorry I can’t be more help; I’m limited on the Unity side but well versed on the Xcode side.
Possible solution:
You need to “hook” into the iAd callback that would tell you that it “failed to load ad with error”. Once you got that notification you would know to trigger your “other” ad’s.
Note: Found this page to list a bunch of helpful links and it looks like you would:
In Xcode:
In the class that is the ADBannerViewDelegate, add the appropriate didFailToReceiveAdWithError method and then
call your “linking” method back to Unity that would trigger the loading of AdMob
Example:
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[self tellUnityToLoadAdMob];
}
-(void)tellUnityToLoadAdMob {
UnitySendMessage(“AdManager”, “ShowAdMob”, “not used”);
}