Hi Everyone ( @AdXxRi123 @jinming_cao @luispedrofonseca ),
Today, I think I finally solved an issue I had with IUnityAdsListener callbacks not occurring in specific conditions. I’m not sure if this will help anyone, but may provide some insight, so I’ll share my experience in trying to figure out Unity Ads.
My fix seems to have been upgrading my project from Unity 2019.1.8f1 to 2019.2.19f1 (and then turning on/off some lightbulb icon in the Scene view), using Unity Hub.
The problem I had in 2019.1.8f1 only occurred when I played the game after the first time on Android. The first time playing my game after Build and Run to my Android device, IUnityAdsListener callback functions would work fine as expected (confirmed via logcat debug lines). If I pressed the Back button, however, and touched the icon to restart the (cached/still exists in Recent Apps/swipe list) game from the Android homescreen, the IUnityAdsListener callbacks would NOT happen. (If I swiped the game off the recent apps list, and played it again, it would work fine but only the first time.)
At some point, I added .RemoveListener(this); in an OnDestroy() of my ads script. I can’t remember exactly, but I think this allowed me to get it working correctly if I replayed the level with the Ad in it (i.e., reloaded the scene) during the first time running the game, i.e. correctly get IUnityAdsListener callbacks. But that was all occurring before a Back button press and restarting the game from the homescreen.
I was about to try .RemoveAllListeners btw, but it looks like I don’t need to go that route. I had been using .AddListener very early in the script, but discovered that, in the problem cases (i.e. non-first fresh runs), Advertiser.listeners already existed. Also, in both working and problem cases, the Ads themselves were already cached or stored from the last time, i.e. .IsReady worked and was true, so basically I would SEE the ads get shown, just not know when they finished in the problem cases. (it seems like the ads got readied from the last time, very soon after Advertisement.Show() was called, and that would survive through restarting the game from homescreen.)
I had been using Unity Ads 3.4.1 and still use it now. In the older install (Unity 2019.1.8f1), I used the Package Manager to downgrade to various other Unity Ads versions mentioned in these threads like 3.4.0, 3.3.1 I think, and 2.0.8 but none solved the problem so I stayed with 3.4.1. I did turn off the extra option in Services “Enable built-in Ads extension” under Advanced, but I don’t think that had much effect actually. I was worried about potential conflicting installs of the libraries/package, and I can’t even remember how I first obtained Unity Ads, whether via the Asset Store or Package Manager, just that I deleted some files/contents after getting it ( @Kaymax knows the process isn’t exactly clear), and it worked mostly, except for my problem. I think I have 3.4.1, but who knows exactly, cause sometimes .version tells me 3.4.0, but I read somewhere .version isn’t always accurate (does Charles know, who is Charles, something about a method to confirm-- but I didn’t do the Charles thing, in any case, to get it working as, well, you know. advertised).
Related threads on IUnityAdsListener callbacks not happening as expected: