sunnycupertino / cordova-plugin-admob-simple

Cordova plugin allowing Admob interstitials and banner ads.
MIT License
164 stars 150 forks source link

Getting "Admob plugin not ready" #48

Closed chinyart closed 5 years ago

chinyart commented 5 years ago

Hi, i am getting this alert from the plugin, that the plugin is not ready AndriodManifest.xml: ` <?xml version='1.0' encoding='utf-8'?>

`

index.js:

    initAd()
showBannerFunc()
function initAd(){
    if ( window.plugins && window.plugins.AdMob ) {
        var ad_units = {
            ios : {
                banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',       //PUT ADMOB ADCODE HERE
                interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE
            },
            android : {
                banner: 'ca-app-pub-4671871274849807/8704622113',       //PUT ADMOB ADCODE HERE
                interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE
            }
        };
        var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;

        window.plugins.AdMob.setOptions( {
            publisherId: admobid.banner,
            interstitialAdId: admobid.interstitial,
            adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, LARGE_BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
            bannerAtTop: false, // set to true, to put banner at top
            overlap: true, // banner will overlap webview
            offsetTopBar: false, // set to true to avoid ios7 status bar overlap
            isTesting: false, // receiving test ad
            autoShow: true // auto show interstitial ad when loaded
        });

        registerAdEvents();
    } else {
        alert( 'admob plugin not ready' );
    }
}
//functions to allow you to know when ads are shown, etc.
function registerAdEvents() {
    document.addEventListener('onReceiveAd', function(){});
    document.addEventListener('onFailedToReceiveAd', function(data){});
    document.addEventListener('onPresentAd', function(){});
    document.addEventListener('onDismissAd', function(){ });
    document.addEventListener('onLeaveToAd', function(){ });
    document.addEventListener('onReceiveInterstitialAd', function(){ });
    document.addEventListener('onPresentInterstitialAd', function(){ });
    document.addEventListener('onDismissInterstitialAd', function(){ });
}

//display the banner
function showBannerFunc(){
    window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
    window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown and show when it's loaded.
    window.plugins.AdMob.requestInterstitialAd();
}

I would appreciate any assistance or idea on how to tackle this issue

sunnycupertino commented 5 years ago

I would try put an interstitial add id in there as well.

chinyart commented 5 years ago

okay.....let me give that a try....thanks

chinyart commented 5 years ago

i have added the interstitial id to the app i am still getting the message "Admob plugin is not ready"

below is a screenshot: https://nedumstudios.com/vghdhfufdygifydgkh_images/admob.png

is there something i am missing? This app is not yet on google play though, could that be the reason for the message?

sunnycupertino commented 5 years ago

Where is initAd() being called? You have to call it after the cordovaready event.

chinyart commented 5 years ago

Below are snapshots of my html and js code:

this one is the arrangement of my libraries cordova.js is above a file custom.js where i kept the function and called initAd() https://nedumstudios.com/vghdhfufdygifydgkh_images/bug4.PNG

this one is the image of the function calling the banner ads https://nedumstudios.com/vghdhfufdygifydgkh_images/bug5.PNG

while this one is the image of the custom.js file where i call the initAd() https://nedumstudios.com/vghdhfufdygifydgkh_images/custom.PNG

sunnycupertino commented 5 years ago

Initad() needs to be called when the document is ready, and not before. That is why it's failing.

chinyart commented 5 years ago

Hi @sunnycupertino i called the initAd() after document is ready not before below is the link with the updated screenshot

https://nedumstudios.com/vghdhfufdygifydgkh_images/custom.PNG

i would appreciate if you would help resolve this issue.

sunnycupertino commented 5 years ago

I'm sorry it's not up to us to debug your code. But at a glance it looks odd what you have done. You have multiple document ready calls, and even functions defined within functions, all if this is out of the ordinary and I have no idea how this kind of thing will behave.

chinyart commented 5 years ago

yeah i noticed that too, got that fixed though i opened a new issue, that is the latest bug/issue i am facing, i got everything in place

checked if the app recognizes the plugin, it does but no ads displaying at all

here is the link to the newly opened issue https://github.com/sunnycupertino/cordova-plugin-admob-simple/issues/50