iAd crashes my app

Hi,
Guys I need help, I created a game and put the iAd code, exactly the way it was written in unity script manual.

http://docs.unity3d.com/Documentation/ScriptReference/ADBannerView.html

I just removed the the line that generates a button to show the iAd so I wrote like this and added this to my main menu script in the scene:

//for iAd banner
function OnGUI() {
    GUI.enabled = (banner == null ? true : false);
    
    banner = new ADBannerView();
    banner.autoSize = true;
    banner.autoPosition = ADPosition.Bottom;
    StartCoroutine(ShowBanner());
}

//iAd function
function ShowBanner() {
    while (!banner.loaded  banner.error == null)
        yield;
        
    if (banner.error == null)
        banner.Show();
    else banner = null;
}

when I ran the app on my iphone, the iAd sample “Sometimes” showed up and most of the times crashed the app (it was random). So I thought the crashes are because of the absence of an actual Ad, and I assumed that it would be fixed when I send it to app store. But now that my app is on app store, not a single app shows up and 90% of the time the app crashes upon the loading of the iAd. Do you guys have any ideas how to fix this?

P.S. I have enabled iAd network on my iTunes connect and using unity 3.5.7f6

Hi, i have the same problem…Also using Unity 3.5.7 and my framerate is well at 25-28 FPS but when the banner loads it goes down to 15-20 and when i click on the test banner from apple it seems to need a lot of memory for loading content and the app crash! Till now i also have no solution for this? Anybody have an idea to free programmaticaly memory when clicking on the banner? Mybe in Objective-c or Unity Javascript?

Thanks

neither. The problem was that I was putting the banner inside OnGUI, which is a loop function, instead change the function type to Start() and everything will be fine. My game is running on app store now, you can take a look
https://itunes.apple.com/us/app/eagle-training/id638328088?ls=1&mt=8

no it isn’t working…also when i call it once and not in gui loop. It always crashes when the iAd Test content is loading.
What else can i do? Thanks

the Unity code is fine, but the issue is that in the unity code there is a button that the user has to touch in order to reveal the ad banner. But in my case I just removed the button and that was the reason of the crash! because without the button function the iad banner code was running 100 times per frame resulting in a crash! So either use the button function which then requires you to put your function inside a OnGUI() function since a GUI element is involved; OR remove the button and place that code inside the Start() function, so it would be executed only once.

hey thanks…so i know now that you forget the button for testing without looping in the OnGUI Function. Thats not my Problem.

My Problem is when i click on the test iad banner.… the content loads for 2-3 seconds and then crashes the app with error:

viewServiceDidTerminateWithError:: Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be completed. (XPCObjectsErrorDomain error 2.)"

Any idea?

hi mikolo
i face some issue with iad and unity 4.2, did u manage to solve your problem?