ratson / cordova-plugin-admob-free

New development has been moved to "admob-plus-cordova", https://github.com/admob-plus/admob-plus/tree/master/packages/cordova
https://github.com/admob-plus/admob-plus
MIT License
495 stars 211 forks source link

"AdMob is not defined" #36

Closed Script47 closed 7 years ago

Script47 commented 7 years ago

I found this plugin and it suited me perfectly, no extra nonsense and very good usability. I got it working and the test ads showed, however for some reason now I keep getting AdMob is not defined. It happens when I run the function showInterstitial(); which I created.

JavaScript

The Initialization

function onReady() {
    AdMob.setOptions({
    publisherId: 'my-id-here',
    interstitialAdId: 'my-id-here',
    bannerAtTop: false,
    overlap: true,
    offsetTopBar: false,
    isTesting: true,
    autoShow: false
    });

    AdMob.prepareInterstitial();
}

document.addEventListener('app.Ready', onReady, false);

The Function

function showInterstitial() {
    AdMob.prepareInterstitial({}, function () {
        AdMob.showInterstitial();
    });
}

I then tried,

function showInterstitial() {
    window.navigator.plugins.AdMob.prepareInterstitial({}, function () {
        window.navigator.plugins.AdMob.showInterstitial();
    });
}

I have tried reinstalling the plugin fresh, but it still didn't work.

Miscellaneous

Software: Intel XDK (3641)

Cordova Version: 6.2.0

ratson commented 7 years ago

I am not sure about Intel XDK. Should the event be deviceready?

Script47 commented 7 years ago

I was using the deviceready event, the issue was that I hadn't included Cordova. Simple fix really,

<script src="cordova.js"></script>

and it was all working, @this question on SO helped me solve this issue.