Search Unity

My Unity Ad works on IOS, but not on Android

Discussion in 'Unity Ads & User Acquisition' started by Fat Kui, Jan 12, 2015.

  1. Fat Kui

    Fat Kui

    Joined:
    Aug 2, 2014
    Posts:
    2
    Hi, I am using the same script on both IOS and Android. Unity Ad works fine on IOS, but it doesn't show up on Android. I knew that Advertisement.isSupported, Advertisement.isInitialized and Advertisement.isReady are true. Have I missed something? Here is part of my script:

    Code (CSharp):
    1. public class UnityAdControl : MonoBehaviour
    2. {
    3.     public string gameID;
    4.     public bool isShowVideo;
    5.     public bool isCheat;
    6.     public bool disableTestMode;
    7.  
    8.     void Awake ()
    9.     {
    10.         if (Advertisement.isSupported)
    11.         {
    12.             Advertisement.allowPrecache = true;
    13.            
    14.             if (Application.platform == RuntimePlatform.IPhonePlayer)
    15.             {
    16.                 gameID = "????"; // IOS Ad ID
    17.             }
    18.             else if (Application.platform == RuntimePlatform.Android)
    19.             {
    20.                 gameID = "????"; // Android Ad ID
    21.             }
    22.            
    23.             bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
    24.             Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
    25.                                     gameID, enableTestMode ? "enabled" : "disabled"));
    26.            
    27.             Advertisement.Initialize(gameID, enableTestMode);
    28.         }
    29.     }
    30.  
    31.     void Update ()
    32.     {
    33.         if (isShowVideo)
    34.         {
    35.             string zoneID = "rewardedVideoZone";
    36.            
    37.             if (string.IsNullOrEmpty(zoneID))
    38.             {
    39.                 zoneID = null;
    40.             }
    41.            
    42.             ShowOptions options = new ShowOptions();
    43.             options.pause = true;
    44.             options.resultCallback = HandleShowResult;
    45.            
    46.             if (Advertisement.isReady(zoneID))
    47.             {
    48.                 Advertisement.Show(zoneID, options);
    49.                 isShowVideo = false;
    50.             }
    51.             else
    52.             {
    53.                 isShowVideo = false;
    54.                
    55.                 if (Application.platform == RuntimePlatform.IPhonePlayer)
    56.                 {
    57.                     IOSNativePopUpManager.showMessage("Video Ad", "Sorry,\nthe Ad is not ready yet!"); // IOS Native Plugin
    58.                 }
    59.                 else if (Application.platform == RuntimePlatform.Android)
    60.                 {
    61.                     AN_PoupsProxy.showMessage("Video Ad", "Sorry,\nthe Ad is not ready yet!"); // Android Native Plugin
    62.                 }
    63.             }
    64.         }
    65.     }
    66.    
    67.     public void HandleShowResult (ShowResult result)
    68.     {
    69.         switch (result)
    70.         {
    71.         case ShowResult.Finished:
    72.             isCheat = true;
    73.             break;
    74.         case ShowResult.Skipped:
    75.             isCheat = false;
    76.             break;
    77.         case ShowResult.Failed:
    78.             isCheat = false;
    79.             break;
    80.         }
    81.     }
    82. }
     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello,
    Im not a pro but in my opinion, you should take Advertisement.Show(zoneID, options); out of Update function. Because maybe on runtime, after 48. line unity ads opens and isShowVideo=false not working. Maybe because it pauses games and its not update anymore. You can use option pause=false if it fits your game.
    This is my opinion.

    Regards,
     
  3. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    It looks like you're trying to show an ad once shortly after your game starts.

    Is this correct?
     
  4. Fat Kui

    Fat Kui

    Joined:
    Aug 2, 2014
    Posts:
    2
    I finally fixed the problem ~~

    Salazar: Thanks for you advice, however, when I move "isShowVideo=false" to somewhere else, the message "Video Ad. Sorry, the Ad is not ready yet!" keep popping up until "Advertisement.isReady" is true.

    Nikkolai: Not really, I want to show the Video Ad whenever the "isShowVideo" is true.

    I found that i could not initialize the advertisement, then i double check the asset files. There are some files of Unity Ads moved to another folder (I guess they move automatically when I import some other plugins). After I moved them to the correct folder, everything is fine.

    Anyway, thanks guys!
     
    Salazar likes this.