react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Admob - rewardedAd.load() and interstitial.load() not working the second time

Open enosh94 opened this issue 6 years ago • 9 comments

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

enosh94 avatar Jun 06 '20 11:06 enosh94

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

Choco-Dev avatar Jun 21 '20 10:06 Choco-Dev

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

enosh94 avatar Jun 25 '20 11:06 enosh94

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

mikehardy avatar Jun 25 '20 20:06 mikehardy

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

Choco-Dev avatar Jun 26 '20 00:06 Choco-Dev

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.

stale[bot] avatar Jul 25 '20 03:07 stale[bot]

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

bamunusingha avatar Aug 02 '20 21:08 bamunusingha

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.

stale[bot] avatar Aug 30 '20 23:08 stale[bot]

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.

stale[bot] avatar Sep 20 '20 03:09 stale[bot]

Facing the same issue. @Choco-Dev solution not working.

Robiullah2244 avatar Feb 28 '23 16:02 Robiullah2244