1

Okay so we are using the unity built in adbannerview. We use the basic code

private ADBannerView banner = null;
void Start()
{
    banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Top);
    ADBannerView.onBannerWasClicked += OnBannerClicked;
    ADBannerView.onBannerWasLoaded  += OnBannerLoaded;
}
void OnBannerClicked()
{
    Debug.Log("Clicked!\n");
}
void OnBannerLoaded()
{
    Debug.Log("Loaded!\n");
    banner.visible = true;
    StartCoroutine(HideBanner);
}

IEnumerator HideBanner()
{ 
    yield return new WaitForSeconds(10);
    banner.visible = false;
    Destroy(this);
}

void OnDestroy()
{
    ADBannerView.onBannerWasClicked -= OnBannerClicked;
    ADBannerView.onBannerWasLoaded  -= OnBannerLoaded;
}

And now once the banner has shown for ten seconds we call we call on Destroy that will unsubscribe from both the events and then destroy the script and empty gameobject that it is on. I know that it is a little extreme, but for some reason in our app it will display the banner at the start of the game, but then for some reason 5 minutes later it will get really laggy and I have pinpointed that it is something to do with the ad trying to receive another one. Because when we didn't fully destroy the adbanner script another ad would load around two minutes and another at 5 minutes. And once we took the ads off there was no lag around five minutes.

Do not know how to fix this.

Steven
  • 166,672
  • 24
  • 332
  • 435
Beastwood
  • 446
  • 3
  • 19
  • I am having similar issues controlling the AdBannerView in Unity. Setting visible to false seems to only work sometimes. Setting the banner to null seems to make the banner not clickable on new scenes. Have you made any progress on this issue? – Kyle Nunery Mar 26 '14 at 23:46
  • Nunery, not at all. It is a pretty bad system. This is what I figured out (might not be 100 percent correct). It is not controlled through Unity. Once you start listening for IAds it is going to keep sending them no matter what you do in Unity. I also talked to ItunesConnect support, which couldn't resolve the issue, and told me to submit a ticket to developer.apple, which I did. They replied saying that they do not deal with IAd since it is a third party. And unfortunately I was not able to dig any deeper since I started working. – Beastwood Mar 31 '14 at 15:11
  • I ended up using the Prime31 plugin in order to get the control I needed for my application. – Kyle Nunery Apr 30 '14 at 00:06
  • same problem her, banner sticks around sometimes and is not clickable when setting visible to false and banner to null – matthias_buehlmann May 18 '14 at 22:00

1 Answers1

0

I could be wrong here also but how it appears to me is that when you call

banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Top);

it actually creates a variable inside of that script but an object outside Unity. As in a view created by the Xcode side of things and your Unity code simply runs inside the OTHER frame it generates for Unity content.

So when you destroy the script, you loose the reference to that object but the object persists outside of your reach. So now, the next time that Start is run it will create yet another object outside of Unity and actually display 2 banners on top of each other. So the more times you call the banner = new line, the slower your project is going to get as it starts loading more and more banners.

AsI understand it, the way you are meant to use this system is to have a bootstrap scene before you get to your main menu. In that scene that will only ever get loaded once, you create your banner there and set the object to not destroy on load. From there you only set it's visibility but never ever destroy it.

From what I understood from the Apple explanation of iAd, when you first register to receive ads, it creates a second view and it manages that view completely. So if I understand it correctly, unity also doesn't have any control over it and you cannot destroy it because Unity is basically running in a child view to the banner view so destroying it would destroy your Unity view also...

Again, I could be wrong but this is how I understand it...

Jacco
  • 1