Search Unity

The ad did not finish due to an error

Discussion in 'Unity Ads & User Acquisition' started by pKallv, Oct 2, 2019.

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

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    I had this working a while ago but now I get "The ad did not finish due to an error".

    I am running ads in testmode.

    Is there any way to identify what the problem is?

    I am in IOS mode and ads is enabled.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class KD_AdsController : MonoBehaviour, IUnityAdsListener
    7. {
    8.  
    9.  
    10.     //string gameId = "3297259";
    11.     #if UNITY_IOS
    12.         private string gameId = "XXXXXX";
    13.     #elif UNITY_ANDROID
    14.         private string gameId = "XXXXXX";
    15.     #endif
    16.  
    17.  
    18.  
    19.     string myPlacementId = "rewardedVideo";
    20.     bool testMode = true;
    21.  
    22.     // Initialize the Ads listener and service:
    23.     public void StartAds()
    24.     {
    25.         print("StartAds");
    26.         Advertisement.AddListener(this);
    27.         Advertisement.Initialize(gameId, testMode);
    28.     }
    29.  
    30.     // Implement IUnityAdsListener interface methods:
    31.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    32.     {
    33.         print("OnUnityAdsDidFinish");
    34.         // Define conditional logic for each ad completion status:
    35.         if (showResult == ShowResult.Finished)
    36.         {
    37.             // Reward the user for watching the ad to completion.
    38.             print("COMPLETE ADS");
    39.             PlayerPrefs.SetString("SETUP ADS DONE", "TRUE");
    40.         }
    41.         else if (showResult == ShowResult.Skipped)
    42.         {
    43.             // Do not reward the user for skipping the ad.
    44.             print("SKIPPED ADS");
    45.         }
    46.         else if (showResult == ShowResult.Failed)
    47.         {
    48.             Debug.LogWarning("The ad did not finish due to an error");
    49.         }
    50.     }
    51.  
    52.     public void OnUnityAdsReady(string placementId)
    53.     {
    54.         print("OnUnityAdsReady");
    55.         // If the ready Placement is rewarded, show the ad:
    56.         if (placementId == myPlacementId)
    57.         {
    58.             Advertisement.Show(myPlacementId);
    59.         }
    60.     }
    61.  
    62.     public void OnUnityAdsDidError(string message)
    63.     {
    64.         print("OnUnityAdsDidError");
    65.         print("Error: " + message);
    66.     }
    67.  
    68.     public void OnUnityAdsDidStart(string placementId)
    69.     {
    70.         print("OnUnityAdsDidStart");
    71.         // Optional actions to take when the end-users triggers an ad.
    72.     }
    73. }
    74.  
    Here is the result:

    StartAds
    OnUnityAdsReady
    OnUnityAdsReady
    OnUnityAdsReady
    OnUnityAdsDidFinish
    The ad did not finish due to an error

    Did not hit: "OnUnityAdsDidError"

    The full error message is:


    The code at CallbackExecutor:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3.  
    4. namespace UnityEngine.Advertisements
    5. {
    6.     [AddComponentMenu("")]
    7.     sealed internal class CallbackExecutor : MonoBehaviour
    8.     {
    9.         readonly Queue<Action<CallbackExecutor>> s_Queue = new Queue<Action<CallbackExecutor>>();
    10.  
    11.         public void Post(Action<CallbackExecutor> action)
    12.         {
    13.             lock (s_Queue)
    14.             {
    15.                 s_Queue.Enqueue(action);
    16.             }
    17.         }
    18.  
    19.         void Update()
    20.         {
    21.             lock (s_Queue)
    22.             {
    23.                 while (s_Queue.Count > 0)
    24.                 {
    25.                     s_Queue.Dequeue()(this);
    26.                 }
    27.             }
    28.         }
    29.     }
    30. }
     
    Last edited: Oct 3, 2019
  2. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    I solved the problem by moving from the Advertising API to the Monetizin g API using this code (I still do not understand why previous code did not work):
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Monetization;
    5.  
    6. public class KD_AdsManager : MonoBehaviour
    7. {
    8.     public string placementId = "rewardedVideo";
    9.     [SerializeField] private GameObject pnl_GO_AdsProtect;
    10.  
    11. #if UNITY_IOS
    12.     private string gameId = "9999999";
    13. #elif UNITY_ANDROID
    14.     private string gameId = "9999999";
    15. #endif
    16.     bool testMode = true;
    17.  
    18.     void Start()
    19.     {
    20.         Monetization.Initialize(gameId, testMode);
    21.  
    22.     }
    23.  
    24.     public void ShowAd()
    25.     {
    26.         StartCoroutine(WaitForAd());
    27.     }
    28.  
    29.     IEnumerator WaitForAd()
    30.     {
    31.         while (!Monetization.IsReady(placementId))
    32.         {
    33.             yield return null;
    34.         }
    35.  
    36.         ShowAdPlacementContent ad = null;
    37.         ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
    38.  
    39.         if (ad != null)
    40.         {
    41.             ad.Show(AdFinished);
    42.         }
    43.     }
    44.  
    45.     void AdFinished(ShowResult result)
    46.     {
    47.         if (result == ShowResult.Finished)
    48.         {
    49.             print("SETUP ADS DONE");
    50.             PlayerPrefs.SetString("SETUP ADS DONE", "TRUE");
    51.             pnl_GO_AdsProtect.SetActive(false);
    52.         }
    53.     }
    54.  
    55. }
    56.  
     
    bakinto likes this.
Thread Status:
Not open for further replies.