react-native-admob / admob

Admob for React Native with powerful hooks and components

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle airplane mode / no internet available?

scottc5 opened this issue · comments

Does anyone have a way to handle airplane mode or no connection available when using this library. Right now for example, my hook line is giving me unhandled promise rejection -> Error while connecting to ad server, when I cant connect to the internet and try to load this line: const { adLoadError, adLoaded, show, load, reward, adPresented, adDismissed } = useRewardedAd(TestIds.REWARDED );

I am not well versed with hooks and I'm not really sure how to go about resolving this or if I should take a different approach? Thanks.

Hi, when error loads fail because internet is not available, adLoadError will be set. You can handle it by checking adLoadError is not undefined. Also, more preferred way is showing ad only if ad is loaded, using adLoaded value. If adLoaded value is true, show your ad, otherwise, just move to next screen.

Corresponding example can be found in Documentation.

Also, I found internal code does not handle promise rejection on the very first load if the ad is loaded automatically thus throws the warning. You can ignore the warning this time. I'll update code to remove the warning in the next version.

Awesome thanks for your response and explanation! Also thanks for looking into the warning!