sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 532 forks source link

adMobRewarded E_AD_FAILED_TO_LOAD #496

Open Tinmania2018 opened 4 years ago

Tinmania2018 commented 4 years ago

So I've been trying to add the adMobRewared to my app but failed to do so. I added a banner on a page without any trouble but this one keeps bugging mee.

The example worked on my IOS emulator so I just copied some code over to my own app.

In the page where the Rewarded ad should be played I added the ComponentDidMount part of the example in a useEffect hook;

useEffect(() => {
        AdMobRewarded.setTestDevices([AdMobRewarded.simulatorId]);
        AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/5224354917');

        AdMobRewarded.addEventListener('rewarded', reward =>
            console.log('AdMobRewarded => rewarded', reward),
        );
        AdMobRewarded.addEventListener('adLoaded', () =>
            console.log('AdMobRewarded => adLoaded'),
        );
        AdMobRewarded.addEventListener('adFailedToLoad', error =>
            console.warn(error),
        );
        AdMobRewarded.addEventListener('adOpened', () =>
            console.log('AdMobRewarded => adOpened'),
        );
        AdMobRewarded.addEventListener('videoStarted', () =>
            console.log('AdMobRewarded => videoStarted'),
        );
        AdMobRewarded.addEventListener('adClosed', () => {
            console.log('AdMobRewarded => adClosed');
            AdMobRewarded.requestAd().catch(error => console.warn(error));
        });
        AdMobRewarded.addEventListener('adLeftApplication', () =>
            console.log('AdMobRewarded => adLeftApplication'),
        );
        AdMobRewarded.requestAd().catch(error => console.warn(error));
    }, [])

When a user entered the information they can add these to the database for free if they look at the ad. So when pushing the right button the addUsingAdHandler is started. This closes a modal (in the modal users get to choose to add information for free) and after that show the ad. const addUsingAdHandler = () => { setIsAddMode(false) console.log('Rewared video is shown') AdMobRewarded.showAd().catch(error => console.warn(error)); }

My console log is logged. However no video is ever shown. When opening the page where the ad should be shown an error is logged. In the emulator I see

{"framesToPop":1, "code": "E_AD_FAILED_TO_LOAD","nativeStackIOS etc. etc.

In my ReactNativeDebugger I receive a warning Error: Cannot send request while another ad is being presented. Another rewarded ad may be requested after the current ad closes.

If I click on the button to view the app (after all these warnings) I receive a warning Error: Ad is not ready.

Screenshot 2020-01-08 at 18 50 47

Can anyone help me with getting this to work?

Tinmania2018 commented 4 years ago

So I thought maybe it was because my own adMob account did not have a AdMob Rewared added, only a Interstitial. So I created the Rewarded in the Admob console however because of the time it would take before this was active I changed the code to show an Interstitial ad.

The code for Interstitial shows no warnings or errors. I wait until the console log AdMobInterstitial adLoaded is shown. After that I push the button to show the app; The modal is closed No ad is shown. The console log shows AdMobInterstitial => adOpened

So the event listener works in logging that the ad is shown, however why am I not seeing anything?

React-native-cli: 2.0.1 React-native: 0.59.10 React-native-admob: 2.0.0-beta.6

usmanuj7 commented 4 years ago

It works fine on android but I'm facing the same issue with Rewarded video Ads on ios 1 - The console log shows AdMobRewarded => adLoaded 2- The console log shows AdMobRewarded => adOpened

Than nothing shows in logs and Ads does not Appear as well.

Tinmania2018 commented 4 years ago

@usmanuj7 I tried my android app but this gives the same warnings and isn't showing apps. I copied in the APP.js file from the example and the add showed without any problem. So it is in my code....

I believe that I cannot use the AdMobRewarded.addEventListeners as I use them in the useEffect hook. Trial and erroring my way trought this. If anyone got this working with hooks and would like to know how.

Tinmania2018 commented 4 years ago

@usmanuj7

I'm at the same point as you are now. My Android app is working with the Rewarded ad, the IOS keeps giving the warnings like above and is not showing anything.

What have you discovered/investigated for getting this to work? Maybe we can make it work and fix this together!

usmanuj7 commented 4 years ago

@Tinmania2018 I have resolved this issue. Previously I was showing the Ads from modal which was causing some issues with Admob callbacks. Now I have implemented the Ads in screen. code is given below

const showAdd = async () => {
    try {

      await AdMobRewarded.requestAd()

      AdMobRewarded.showAd()
    } catch (e) {
      console.tron.log(e.message)
    }
  }

  React.useEffect(() => {
    Platform.OS == "ios"
      ? AdMobRewarded.setAdUnitID("ca-app-pub-3940256099942544/1712485313")
      : AdMobRewarded.setAdUnitID("ca-app-pub-3940256099942544/5224354917")

    AdMobRewarded.addEventListener("rewarded", reward => {
      console.log('AdMobRewarded => rewarded', reward)
    })
    AdMobRewarded.addEventListener("adLoaded", () => {
      console.log('AdMobRewarded => add loaded')
    }) 

    AdMobRewarded.addEventListener("adFailedToLoad", error => {
      console.log('AdMobRewarded => failed to load')
    })

    AdMobRewarded.addEventListener("adLeftApplication", () => {
      console.log('AdMobRewarded => add left the application')
    })
    return () => {
      AdMobRewarded.removeAllListeners()
    }
  }, [])
Tinmania2018 commented 4 years ago

@Tinmania2018 I have resolved this issue. Previously I was showing the Ads from modal which was causing some issues with Admob callbacks. Now I have implemented the Ads in screen. code is given below

Awesome work @usmanuj7

I also have a modal come up, in this modal the users can click on a free upload. However I believe I received the warning inmediatly when opening the page. So I have to remove the modal entirely for this to work as expected?

usmanuj7 commented 4 years ago

@Tinmania2018 You need to call the show ads callback from screen not from modal. I had the same issue. I was showing the Rewarded video Ads from modal.

what you can do is you can create a flag and update that flag from modal (onClick action) than create a check in that particular screen to show the rewarded video Ad. It perfectly works for me.