Hi there.
I'm having difficulty with callbacks when rewarded ads are shown. I have followed the guide on setting up rewarded ads, and they appear in my application. My difficulty is in covering all code paths once the ad is shown.
I am using the Unity Admob SDK.
I understand that when I want to show an ad I pass in a callback that is called when the user has earned a reward, e.g (snippets taken from your
getting started guide ):
rewardedAd.Show((Reward reward) =>
{
// TODO: Reward the user.
Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
});
I also understand that to track when the Ad is finished I need to add two additional event listeners. e.g.
// Raised when the ad closed full screen content.
ad.OnAdFullScreenContentClosed += ()
{
Debug.Log("Rewarded Ad full screen content closed.");
// Reload the ad so that we can show another as soon as possible.
LoadRewardedAd();
};
// Raised when the ad failed to open full screen content.
ad.OnAdFullScreenContentFailed += (AdError error) =>
{
Debug.LogError("Rewarded ad failed to open full screen content " +
"with error : " + error);
// Reload the ad so that we can show another as soon as possible.
LoadRewardedAd();
};
As far as I can tell, there are three possible outcomes when i try to show an ad.
- The ad fails to show and no reward is given. The OnAdFullScreenContentFailed event fires.
- The ad shows and a reward is given. The RewardEarned callback is called, and the OnAdFullScreenContentClosed is called - but the ordering is not defined and in some cases dependent on mediation partners
- The ad shows and no reward is given. The OnAdFullScreenContentClosed is called.
The API design seems a little strange. My application needs to prepare the UI when the ad is shown, and then to respond with appropriate feedback when the one of the three outcomes above is known.
My question is: In my implementation, how am I supposed to distinguish between 2 and 3? When I get the Closed event, do I have to check to see if I have already received a RewardEarned call, and if not - wait for it? for how long? When do I know that the ad has been displayed but no reward given? I am hoping that I am mistaken and that outcome 3 is not even possible.
regards,
Julian