react-native-google-mobile-ads
react-native-google-mobile-ads copied to clipboard
RewardedAd.show() The requested RewardedAd has not loaded and could not be shown.
I am trying to load RewardedAd but it shows me this error : RewardedAd.show() The requested RewardedAd has not loaded and could not be shown
This is My Code :
import React, { useEffect, useState } from 'react';
import { Button, View } from 'react-native';
import {
RewardedAd,
RewardedAdEventType,
TestIds
} from 'react-native-google-mobile-ads';
const adUnitId = **DEV**
? TestIds.REWARDED
: 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
const rewarded = RewardedAd.createForAdRequest(adUnitId, {
keywords: ['fashion', 'clothing'],
});
const MyApp = () => {
const [loaded, setLoaded] = useState(false);
useEffect(() => {
const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
setLoaded(true);
});
const unsubscribeEarned = rewarded.addAdEventListener(
RewardedAdEventType.EARNED_REWARD,
reward => {
console.log('User earned reward of ', reward);
},
);
// Start loading the rewarded ad straight away
rewarded.load();
// Unsubscribe from events on unmount
return () => {
unsubscribeLoaded();
unsubscribeEarned();
};
}, []);
console.log('loaded===', loaded);
return (
<View>
<Button
title="Show Rewarded Ad"
onPress={() => {
rewarded.show();
}}
/>
</View>
);
};
export default MyApp;
Platforms
Only on Android
package.json
"react": "18.2.0",
"react-native": "0.71.8",
"react-native-google-mobile-ads": "^12.6.0",
app.json
{
"name": "MyApp",
"displayName": "MyApp",
"react-native-google-mobile-ads": {
"android_app_id": "ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy"
}
}
Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
FYI - we see this issue in production. We check the ad is loaded immediately before showing a dialog with the option to watch the ad for the "reward" but some smallish percentage of the time we hit this error anyway.
I know the code above is direct from the documentation but you should definitely check the ad is actually loaded before trying to show it.
Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.