iAd discussion question

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?

I would but I don’t have a mac until the weekend. I have to borrow a friends. I just am trying to get all my code figured out before then.

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?

I always see a test ad displayed until the app is approved by Apple.

just checking this script will only compile on a mac?

@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…

iphone works fine, although the test ad eventually turns into a plain white banner and im not sure if this is normal behaviour

Meh I’m gonna check some more then, my banner may be obscured by an error of placement then.

@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!

it’s called adwhirl folks and the kindly mr prime31 with his top hat and white gloves is ready to dazzle you

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.

just to confirm this… my app went live but after the first advert it will not refresh correctly. Problem with unity.

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?

You can compare and try the original code I copied and modified from the AdBannerView documentation in the Scripting REference.

Oh I didnt mean you had introduced a bug with your rewrite or anything :wink:
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.