React-native-firebase: Admob - rewardedAd.load() and interstitial.load() not working the second time

Created on 6 Jun 2020  路  8Comments  路  Source: invertase/react-native-firebase

Hey I'm experiencing the same error raised here #3185 again on adMob Version "^7.1.3". I checked with interstitial.load() and It also does not work for the second time.

( Note: ads are getting loaded for the first time. but not for the second time)

Annotation 2020-06-06 165625

AdMob Stale

Most helpful comment

i was struggling with same problem for past 2 days and i just could get over it today.
this is the solution that works for me.
you should create a ref from the RewardedAd.createForAdRequest() instead of creating an object of it out of component's function. this way we can have a fresh new object of rewardedAd in our component.

const ComponentName = () => {
  const rewardedAdRef = useRef(RewardedAd.createForAdRequest(TestIds.REWARDED));
  const [adLoaded, setAdLoaded] = useState(false);

  useEffect(() => {
    const eventListener = rewardedAdRef.current.onAdEvent((type) => {
      if (type === RewardedAdEventType.LOADED) setAdLoaded(true);
    });

    // Start loading the interstitial straight away
    rewardedAdRef.current.load();

    // Unsubscribe from events on unmount
    return () => {
      eventListener();
    };
  }, []);

  if(adLoaded)
    return <Button title="Show ad" onPress={() => rewardedAdRef.current.show()} />;

  return null;
}

All 8 comments

i was struggling with same problem for past 2 days and i just could get over it today.
this is the solution that works for me.
you should create a ref from the RewardedAd.createForAdRequest() instead of creating an object of it out of component's function. this way we can have a fresh new object of rewardedAd in our component.

const ComponentName = () => {
  const rewardedAdRef = useRef(RewardedAd.createForAdRequest(TestIds.REWARDED));
  const [adLoaded, setAdLoaded] = useState(false);

  useEffect(() => {
    const eventListener = rewardedAdRef.current.onAdEvent((type) => {
      if (type === RewardedAdEventType.LOADED) setAdLoaded(true);
    });

    // Start loading the interstitial straight away
    rewardedAdRef.current.load();

    // Unsubscribe from events on unmount
    return () => {
      eventListener();
    };
  }, []);

  if(adLoaded)
    return <Button title="Show ad" onPress={() => rewardedAdRef.current.show()} />;

  return null;
}

Thank you so much @Choco-Dev . your solution worked well.

If there is some problem with the library functionality and there is a working solution, please propose a PR! it will help everyone

i would like to help but i'm not familiar with the codes on this repo @mikehardy :) so i'm going to describe the way i could reproduce the problem for anyone who wants to work on it:

  1. go to the screen where the ad is going to be loaded.
  2. get back to previous screen.
  3. then again go the same screen to see if the ad can get loaded for the second time.

packages i was using with my RN project:

  • @react-navigatio: >5.0.0
  • @react-native-firebase/admob: 7.2.0

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 the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

Still having the issue with @react-native-firebase/admob: 7.3.3

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 the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

Was this page helpful?
0 / 5 - 0 ratings