react-native-google-mobile-ads icon indicating copy to clipboard operation
react-native-google-mobile-ads copied to clipboard

RewardedAd.show() The requested RewardedAd has not loaded and could not be shown.

Open SaGaR1084 opened this issue 1 year ago • 2 comments

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

Screenshot 2023-12-29 at 12 04 57 PM

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"
  }
}

SaGaR1084 avatar Dec 27 '23 11:12 SaGaR1084

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.

github-actions[bot] avatar Jan 26 '24 06:01 github-actions[bot]

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.

markwilcox avatar Feb 02 '24 15:02 markwilcox

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.

github-actions[bot] avatar Mar 01 '24 16:03 github-actions[bot]