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

So this is my code, which is kinda similiar to the one from the snippet generator:

void AdShown(object sender, EventArgs args)
{
      Unity.Services.Mediation.RewardedAd adShown = ((Unity.Services.Mediation.RewardedAd) sender);
      adShown.Load();
      Debug.Log("Ad shown!");
}

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.
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

For a workaround, I’ve ended up doing a coroutine to wait until the ad is not showing anymore:

    IEnumerator LoadCoroutine(Unity.Services.Mediation.RewardedAd ad){
        while(ad.AdState == AdState.Showing){
            yield return new WaitForSeconds(0.25f);
        }

        ad.Load();  
    }

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.

void AdClosed(object sender, EventArgs e)
{
     // Ad has been closed, load another.
     ad.Load();
}

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!

Thanks for pointing this out, this has since been addressed and will be fixed when the next version is available.