Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug IRewardedAd.OnShowed is called when the ad is currently showing on iOS

Discussion in 'Unity Mediation' started by pablo_leban, Dec 10, 2021.

  1. pablo_leban

    pablo_leban

    Joined:
    Sep 19, 2013
    Posts:
    40
    So this is my code, which is kinda similiar to the one from the snippet generator:

    Code (CSharp):
    1. void AdShown(object sender, EventArgs args)
    2. {
    3.       Unity.Services.Mediation.RewardedAd adShown = ((Unity.Services.Mediation.RewardedAd) sender);
    4.       adShown.Load();
    5.       Debug.Log("Ad shown!");
    6. }
    AdShown() is being called when the ad is currently showing on my iPad but not after it has been shown, so the Load() fails.

    Thus, I'm getting the following error on Xcode:

    You cannot call load on a currently showing ad.
    <UNIT ID> is currently showing.


    This makes impossible to watch the ad again after the first one is shown.

    I'm on Unity 2020.3.24f1, Mediation Package 0.3.0-preview.3
     
  2. pablo_leban

    pablo_leban

    Joined:
    Sep 19, 2013
    Posts:
    40
    For a workaround, I've ended up doing a coroutine to wait until the ad is not showing anymore:

    Code (CSharp):
    1.     IEnumerator LoadCoroutine(Unity.Services.Mediation.RewardedAd ad){
    2.         while(ad.AdState == AdState.Showing){
    3.             yield return new WaitForSeconds(0.25f);
    4.         }
    5.  
    6.         ad.Load();  
    7.     }
    8.  
     
  3. MonishGupta

    MonishGupta

    Unity Technologies

    Joined:
    May 30, 2018
    Posts:
    9
    Hey pablo!

    We recommend using the OnClosed callback to reload your ads. This callback guarantees that the ad instance will not be showing and will be triggered when the ad instance finishes. A coroutine isn't necessary here. In case of failure to load or show an ad you can subscribe to OnFailedLoad and OnFailedShow and perform an ad.Load() there.

    Code (CSharp):
    1. void AdClosed(object sender, EventArgs e)
    2. {
    3.      // Ad has been closed, load another.
    4.      ad.Load();
    5. }
     
  4. pablo_leban

    pablo_leban

    Joined:
    Sep 19, 2013
    Posts:
    40
    Hi! Monish! Thanks for the reply!

    Then the code generator should be updated so it's in the OnClosed instead of the OnShowed.



    Thank you!
     
  5. MonishGupta

    MonishGupta

    Unity Technologies

    Joined:
    May 30, 2018
    Posts:
    9
    Thanks for pointing this out, this has since been addressed and will be fixed when the next version is available.