I am looking into some of the iAd functionality that Unity provides and I was wondering if this is all I have to call in order to have iAd into my game. I know that I have to setup the iAd in the apple development section, but is this all I have to call in Unity to display it?
private var banner : ADBannerView = null;
function ShowBanner() {
while (!banner.loaded banner.error == null)
yield;
if (banner.error == null)
banner.Show();
else banner = null;
}
function OnGUI() {
GUI.enabled = (banner == null ? true : false);
if (GUILayout.Button("Show Banner")) {
banner = new ADBannerView();
banner.autoSize = true;
banner.autoPosition = ADPosition.Bottom;
StartCoroutine(ShowBanner());
}
}
I wouldn’t use a button to display the ad but is this the only call I need to make?
It’s pretty simple to create an iAd. I haven’t tested the specific script you posted, but just glancing over it, it appears like it should work fine. Why don’t you test it yourself?
That script is from the Script Reference for AdBannerView so I’d expect it to work. I have a button-less version listed here - http://drupal.technicat.com/games/unity/ios/iads.html - but it seems to me that it doesn’t refresh the ad after the first one is displayed, so I’ve filed a bug report.
Thanks technicat. Yeah I haven’t done much work with ads in my game so I just am unsure on how they actually get displayed. Will this show up in my development version? Or does it only work in published versions?
@technicat: Does it work for you on iPhone? Because I can display the test ad on my iPad, but there’s nothing showing on my iPhone, eventhough my Debug Logs say the opposite…
@Le_nain It does show up for me on my 4th-gen iPod touch (iOS 5) but will disappear if I suspend and resume - I assume it’s the same non-refreshing issue that produces the white banner. @nshack31 re your earlier question, the doc only mentions an implementation of AdBannerView for iAds (and thus, only on iOS) - I would hope the code compiles and does nothing for non-IOS targets but if not, you can just wrap an #if UNITY_IPHONE around it.
Found it: the issue relies in the retina display.
Let me explain in case someone has the same issue someday:
First, I’m not using like you guys the autposition/autosize features, because as within my app I manually handle the screen rotations (not using Unity’s autorotation because I want to change some settings on my camera/GUI when the screen rotates), it wouldn’t autoposition nor autosize my banners.
So I was manually positionning my banners, but I was doing it the way it should be handled by Unity: using Screen.height - the Y size of my banner. Here’s lies the problem. in fact, Unity just transfers those parameters to native and let it handles the banners. THOUGH, one should know that Apple’s SDK handles retina and non-retina displays the exact same way, so even if you’re on a retina display device you should use the non-retina display screen sizes to place your banner. (e.g. for iPhone 3 AND iPhone 4, the banner should be placed vertically at 320 - bannerYSize for landscape and 480 - bannerYSize for portrait if you want your banner at the bottom)
You guys should also keep in mind that fillrate of real ad request is only around 15% depending on the country. So for most countries you will never see an iAd! Only 7 countries are supported. Make sure to support other ad networks if iAd fails to deliver!
Actually every ad network is getting on the mediation layer train, means trying something similar like adwhirl. Prime has also similar solutions to adwhirl. There is also some free stuff in the asset store. I decided to use Prime’s MoPub. MoPub gives you the possibility to use other ad networks via http requests so that you don’t need to integrate SDKs other than MoPubs. Means less dependencies to third party software and you can easily change the networks via their web interface on the fly.
yeah, I’m using the same code and the ads disappear after the first one… could it just be the buttonless code that Technicat kindly provided is missing something?
Oh I didnt mean you had introduced a bug with your rewrite or anything
I should have said: Could there be something that could be added to the buttonless code that wasnt in the documentation to begin with?
That’s a good point (and I just remembered the doc example is conveniently in the original post here). Maybe we have to periodically check AdBannerView properties like error/loaded/visible and call Show again, but that seems pretty complicated (at least compared to how the Prime31 plugin is used). I haven’t heard anything back from my bug report, either.