native_admob_flutter icon indicating copy to clipboard operation
native_admob_flutter copied to clipboard

[iOS] [NativeAd] Strange refresh behaviors in some situations after 1 minute

Open ramtinq opened this issue 4 years ago • 3 comments

In the example app if we add TickerProviderStateMixin to the class where NativeAds are placed, the ad to which a NativeAdController is attached will refresh to "error" after almost 1 minute, especially if we go back and forth to the second page of NativeAds.

Another situation which will cause such behavior is when we remove the ListView, put only 1 NativeAd with controller in the page, and do not check if (controller.isLoaded) . The NativeAd will appear as soon as it's loaded, then after 1 minute it will refresh to "error" (the parent widget should have to rebuild itself for seeing this effect, like switching tabs in IndexedStack with BottomNavigationBar).

These don't happen in Android at all. And currently, I've tested it only in iOS Simulator. Soon I'll check it in a real iOS device.

As you can see in the screenshots below, the first ad which had a controller attached to it is disappeared (after tapping the top right arrow to go to the next page and coming back. This will not happen if we do it when less than 1 minute is passed after the ad is loaded for the first time.

Simulator Screen Shot - iPhone 12 Pro Max - 2021-06-07 at 15 30 51

And now the first ad is disappeared (because controller.isLoaded is switched to false ! )

Simulator Screen Shot - iPhone 12 Pro Max - 2021-06-07 at 15 32 51

ramtinq avatar Jun 07 '21 11:06 ramtinq

Well, after hours of experimenting, I found out that there's a timeout attribute in controller.load method with which we can set to a long time so that ad won't try to reload! But why this does not happen in android?! Without setting any timeout, the ad will not change after a minute is passed.

And how can we set timeout to infinity? because in Google's documents it is stated that NativeAds do not have a refresh rate by default.

I think we should also update documents to clarify what is the correct implementation of NativeAds. After setting timeout to a long time, it's not even needed to check controller.isLoaded to show the NativeAd which the controller is attached to! All the weird artifacts are gone!

ramtinq avatar Jun 07 '21 13:06 ramtinq

This may be related to hybrid composition

bdlukaa avatar Jun 09 '21 13:06 bdlukaa

Another thing I wanted to propose was some clarity on using controller in a correct way (or re-writing the way a controller works). In the example app there's an if statement to check wether the controller is loaded or not, to decide wether to add its NativeAd to widget tree. This seems reasonable but not necessary. That's because the NativeAd widget loads another ad if the controller attached to it has not laded yet, although we've set its controller: attribute to a NativeAdController object. I think such dual behavior yields to ambiguity. It took myself several hours to find out why my controller.isLoaded shows false while the ad had already showed up.

proposal: if an ad's controller: variable is set, it should work and display ads only based on its controller object.

ramtinq avatar Jul 03 '21 13:07 ramtinq