Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iAd and unity 3.5 ADBannerView

Discussion in 'iOS and tvOS' started by Decco, Jun 13, 2012.

  1. Decco

    Decco

    Joined:
    Jun 13, 2012
    Posts:
    3
    Hello,

    I'm trying to set up iAd banner in my game.
    I have tried all the code samples I have found on the forum :

    Code (csharp):
    1.  
    2. private var banner : ADBannerView = null;
    3.    
    4. function ShowBanner() {
    5.     while (!banner.loaded  banner.error == null)
    6.         yield;
    7.        
    8.     if (banner.error == null)
    9.         banner.Show();
    10.     else banner = null;
    11. }
    12.  
    13. function OnGUI() {
    14.     GUI.enabled = (banner == null ? true : false);
    15.    
    16.     if (GUILayout.Button("Show Banner")) {
    17.         banner = new ADBannerView();
    18.         banner.autoSize = true;
    19.         banner.autoPosition = ADPosition.Bottom;
    20.         StartCoroutine(ShowBanner());
    21.     }
    22. }
    23.  
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class iAD : MonoBehaviour {
    6.   IEnumerator Start () {
    7. #if UNITY_IPHONE
    8.         ADBannerView banner = new ADBannerView();
    9.         banner.autoSize = true;
    10.         banner.autoPosition = ADPosition.Bottom;
    11.  
    12.         while (true) {
    13.             if (banner.error != null) {
    14.                 Debug.Log("Error: " + banner.error.description);
    15.                 break;
    16.             } else if (banner.loaded) {
    17.                 banner.Show();
    18.                 break;
    19.             }
    20.             yield return null;
    21.         }
    22. #endif
    23.    
    24. }
    25. }
    26.  
    Code (csharp):
    1.  
    2. // don't make this a local variable, or else it'll get garbage collected
    3. private var banner:ADBannerView;
    4.  
    5. function Start () {
    6.     GameObject.DontDestroyOnLoad(this); // keep ad alive if we load a new scene
    7.     banner = new ADBannerView();
    8.     banner.autoSize = true;
    9.     banner.autoPosition = ADPosition.Bottom;
    10.     while (!banner.loaded  banner.error == null)
    11.         yield;
    12.     if (banner.error == null)
    13.         banner.Show();
    14.     else banner = null;
    15. }
    16.  
    But nothing seems to work. Even the test ads does not show neither in the editor view nor on the iphone.
    Am I missing something ? Do I have to enable something in iAd network for development testing purpose ?
    Do I have to include some lib in the build ? Does anyone successfully use it ?
     
  2. Deleted User

    Deleted User

    Guest

    The ads will not show up in the Editor but they should show up on the device. You do need to enable iAds in iTunesConnect for your app at some point for real ads to show up, but I don't know if that affects test ads.
     
  3. Decco

    Decco

    Joined:
    Jun 13, 2012
    Posts:
    3
    The game is not yet published, so how can I activate the iAd in iTunes connect ?
    I saw every where screenshot with a test banner from iAd. Should I see it on the iphone or not when I click Build Run from unity ?

    I saw you were using one of those code ? Does it work for you ?
     
  4. Deleted User

    Deleted User

    Guest

    Yes, I wrote that last piece of code and it works for me. When you add your app to iTunesConnect there is an option to enable/disable iAds - this option is only available when you first add the app and when you submit updates. At that point you should get test ads until the ad is approved, and then Apple will enable the real ads.
     
  5. Decco

    Decco

    Joined:
    Jun 13, 2012
    Posts:
    3
    Thank you for the info ;-)

    How do you try your code before submitting your app ?
    Does the test banner show up if you have not submited the app ?

    I have build a new project, with just a scene with a camera and an empty gameobject. I have attached your code to the gameobject. Clicked on build and run ...
    No test ad banner show on iphone ...

    Do the iphone have to be connected to the internet (wifi or 3G) to show test banner ?
    Any configuration needed on xcode ? Any library to include ?

    Thank you for your help ;-)
     
  6. Lennon Petrick

    Lennon Petrick

    Joined:
    Sep 30, 2013
    Posts:
    2