Search Unity

No Unity Ads working.

Discussion in 'Unity Ads & User Acquisition' started by altair2020, Aug 26, 2019.

Thread Status:
Not open for further replies.
  1. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    48
    Hello everyone,

    I am using unity: 2018.2.21f

    I have tried the following:

    Package Manager:
    Unity Ads 2.0.8
    Unity Ads 2.3.1

    Also i have removed the Ads package manager and have used the asset store package:

    Unity Monetization 3.2.0

    My code works fine in test mode, with any versions of Ads above, i see the unity "test ad" and all appears to be working... but when i deploy to IOS release i dont get any adverts.

    Can anyone help?

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Advertisements;
    6. public class Advertising : MonoBehaviour //, IUnityAdsListener
    7. {
    8.     private static Advertising advertising = null;
    9.     //---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
    10. #if UNITY_IOS
    11.     private string gameId = "XXXXXXX"; // found on unity developer portal -> settings -> general.
    12. #elif UNITY_ANDROID
    13.     private string gameId = "XXXXXXX"; // found on unity developer portal -> settings -> general.
    14. #endif
    15.     //-------------------------------------------------------------------//
    16.     //public string placementId = "rewardedVideo";
    17.     public string placementId = "shopbanner";
    18.     public float maxTimeBetweenAds = 300f;
    19.     public bool TimeToShowAdBreak = true;
    20.     public bool testMode = false;
    21.     public bool GamePurchased = false;
    22.     IEnumerator NewTest()
    23.     {
    24. #if !UNITY_ADS // If the Ads service is not enabled...
    25.         if (Advertisement.isSupported)
    26.         { // If runtime platform is supported...
    27.             Advertisement.Initialize(gameId, testMode); // ...initialize.
    28.         }
    29. #endif
    30.         // Wait until Unity Ads is initialized,
    31.         // and the default ad placement is ready.
    32.         while (!Advertisement.isInitialized || !Advertisement.IsReady())
    33.         {
    34.             yield return new WaitForSeconds(0.5f);
    35.         }
    36.         // Show the default ad placement.
    37.         Advertisement.Show();
    38.     }
    39.     void Awake()
    40.     {
    41.         if (advertising == null)
    42.         {
    43.             advertising = this;
    44.             DontDestroyOnLoad(this.gameObject);
    45.             return;
    46.         }
    47.         Destroy(this.gameObject);
    48.     }
    49.     void Start()
    50.     {
    51. #if !UNITY_ADS // If the Ads service is not enabled...
    52.         if (Advertisement.isSupported)
    53.         { // If runtime platform is supported...
    54.             Advertisement.Initialize(gameId, testMode); // ...initialize.
    55.         }
    56. #endif
    57.         //StartCoroutine(NewTest());
    58.     }
    59.     public IEnumerator ResetAdTimer()
    60.     {
    61.         yield return new WaitForSeconds(maxTimeBetweenAds); // waits TimeToShowAdBreak seconds
    62.         TimeToShowAdBreak = true; // allow ads again.
    63.     }
    64.     public void ShowAdvert()
    65.     {
    66. #if UNITY_IOS || UNITY_ANDROID
    67.         ShowOptions options = new ShowOptions();
    68.         options.resultCallback = HandleShowResult;
    69.         //Advertisement.Show(placementId, options);
    70.         Advertisement.Show();
    71. #endif
    72.     }
    73.     public void ShowAd()
    74.     {
    75.         if (GamePurchased)
    76.         {
    77.             Debug.LogWarning("GamePurchased: " + GamePurchased);
    78.             gameObject.SetActive(false);
    79.             return;
    80.         }
    81.         Debug.LogWarning("TimeToShowAdBreak: " + TimeToShowAdBreak);
    82.         if (TimeToShowAdBreak)
    83.         {
    84.             Debug.LogWarning("Advertisement.isSupported: " + Advertisement.isSupported);
    85.             Debug.LogWarning("Advertisement.isShowing: " + Advertisement.isShowing);
    86.             if (!Advertisement.isShowing)
    87.             {
    88.                 StartCoroutine(ShowTheAd());
    89.             }
    90.         }
    91.     }
    92.     IEnumerator ShowTheAd()
    93.     {
    94.         Debug.LogWarning("Advertisement.IsReady: " + Advertisement.IsReady());
    95.         while (!Advertisement.isInitialized || !Advertisement.IsReady())
    96.         {
    97.             yield return new WaitForSeconds(0.5f);
    98.         }
    99.         Debug.LogWarning("Advertisement.IsReady: " + Advertisement.IsReady());
    100.         Debug.LogWarning("Trying to ShowAd");
    101.         // Show Advert.
    102.         ShowAdvert();
    103.         // Disable ads from showing up.
    104.         TimeToShowAdBreak = false;
    105.         // Start count down to show ads again.
    106.         StartCoroutine(ResetAdTimer());
    107.     }
    108. #if UNITY_IOS || UNITY_ANDROID
    109.     private void HandleShowResult(ShowResult result)
    110.     {
    111.         switch (result)
    112.         {
    113.             case ShowResult.Finished:
    114.                 Debug.Log("The ad was successfully shown.");
    115.                 //
    116.                 // YOUR CODE TO REWARD THE GAMER
    117.                 // Give coins etc.
    118.                 break;
    119.             case ShowResult.Skipped:
    120.                 Debug.Log("The ad was skipped before reaching the end.");
    121.                 break;
    122.             case ShowResult.Failed:
    123.                 Debug.LogError("The ad failed to be shown.");
    124.                 break;
    125.         }
    126.     }
    127. #endif
    128.     public void SetGamePurchased(bool bol)
    129.     {
    130.         GamePurchased = bol;
    131.     }
    132.     //public void OnUnityAdsReady(string placementId)
    133.     //{
    134.     //    throw new System.NotImplementedException();
    135.     //}
    136.     //public void OnUnityAdsDidError(string message)
    137.     //{
    138.     //    throw new System.NotImplementedException();
    139.     //}
    140.     //public void OnUnityAdsDidStart(string placementId)
    141.     //{
    142.     //    throw new System.NotImplementedException();
    143.     //}
    144.     //public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    145.     //{
    146.     //    throw new System.NotImplementedException();
    147.     //}
    148. }
    149.  
    150.  
    151.  
    Cheers,
    John
     
    Last edited: Aug 26, 2019
  2. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    48
    I got this working... i have modified the above code to show how it works using Unity Monetization 3.2.0 only.
     
Thread Status:
Not open for further replies.