我的ionic / phonegap应用程序使用cordova admob pro插件.
admob在真实设备上可以正常工作,但是当我查看chrome的控制台时发现一个错误:
Uncaught ReferenceError: AdMob is not defined
这是我的整个admob代码:
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = {
banner: '',
interstitial: ''
};
}
if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}
function initApp() {
//Error here
AdMob.createBanner( {
adId: admobid.banner,
isTesting: false,
overlap: false,
offsetTopBar: false,
position: AdMob.AD_POSITION.BOTTOM_CENTER//,
//bgColor: 'yellow'
} );
//And here
AdMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: true //kalo mau bisa false, nanti panggil manual
});
}
错误发生在AdMob.createBanner和AdMob.prepareInterstitial.
如果我将其保留,此错误是否安全? (因为admob运行正常)
有什么办法可以消除此错误?
非常感谢你的帮助
解决方法:
如果您不在移动环境中运行应用程序,则会收到此错误消息.
Uncaught ReferenceError: AdMob is not defined
admob是cordova插件.因此它将在chrome的控制台中显示错误.
为了避免这个错误.
if(window.cordova) {
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) {
admobid = {
banner: '',
interstitial: ''
};
}
if ((/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent))) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}
function initApp() {
//Error here
AdMob.createBanner({
adId: admobid.banner,
isTesting: false,
overlap: false,
offsetTopBar: false,
position: AdMob.AD_POSITION.BOTTOM_CENTER //,
//bgColor: 'yellow'
});
//And here
AdMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: true //kalo mau bisa false, nanti panggil manual
});
}
}
谢谢