Open Seventro opened 1 month ago
The same issue, successfully loaded in the simulator, but unable to load successfully in the real machine
I had the same issue on both Android and iOS devices. This error occurs due to the requestId in MobileAd.ts of the library. In the following code, the requestId is passed to the load method:
public load() {
// Prevent multiple load calls
if (this._loaded || this._isLoadCalled) {
return;
}
this._isLoadCalled = true;
const load: AdLoadFunction = NativeModules[this._nativeModule][`${this._camelCaseType}Load`];
load(this._requestId, this._adUnitId, this._requestOptions);
}
In my case, the problem was happening because when calling load, a requestId was being passed, and when calling show, another requestId was being passed. This indicated that different instances were being called. The solution I implemented and that worked was to add RewardedAd.createForAdRequest inside the useEffect, as shown below:
const [loaded, setLoaded] = useState(false);
let rewarded;
useEffect(() => {
rewarded = RewardedAd.createForAdRequest(constants.adUnitIdRewarded, {
requestNonPersonalizedAdsOnly: true
});
const loadAd = () => {
console.log('Loading rewarded ad');
rewarded.load();
};
const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
console.log('Rewarded ad loaded');
setLoaded(true);
});
const unsubscribeEarned = rewarded.addAdEventListener(RewardedAdEventType.EARNED_REWARD, reward => {
console.log('Reward earned:', reward);
});
const unsubscribeClosed = rewarded.addAdEventListener(AdEventType.CLOSED, () => {
console.log('Rewarded ad closed');
setLoaded(false);
loadAd();
});
const unsubscribeFailed = rewarded.addAdEventListener(AdEventType.ERROR, error => {
console.error('Failed to load rewarded ad:', error);
setLoaded(false);
});
loadAd();
return () => {
unsubscribeLoaded();
unsubscribeEarned();
unsubscribeClosed();
unsubscribeFailed();
};
}, [loaded]);
const showRewardedAd = () => {
rewarded.show();
};
See if this solution works for you as well.
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.
What happened?
So I am making a basic normal 2D game in react native and I in my game if user wants more coins then he can watch Rewarded Ad, So I implemented Rewarded Ads in my Page. But the problem is The ad is not loading, it fails everytime, I tried every solution but still facing same problem.
Error : RewardedAd.show() The requested RewardedAd has not loaded and could not be shown
Here is my Wallet.Js code (I Removed the CSS from this code, so you can focus on main code) :
Platforms
iOS, but have not tested behavior on Android
React Native Info
Are your using Typescript?
package.json
app.json
ios/Podfile
android/build.gradle
No response
android/app/build.gradle
No response
android/settings.gradle
No response
AndroidManifest.xml
No response