cordova admob插件工作但未捕获引用错误

时间:2015-11-13 08:56:47

标签: javascript cordova admob ionic

my ionic / phonegap应用使用cordova admob pro插件。

admob在真实设备上运行正常,但是当我查看Chrome console时发现了一个错误:

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.createBannerAdMob.prepareInterstitial

如果我离开它,这个错误是否安全? (因为admob工作正常)

有没有办法摆脱这个错误?

非常感谢你的帮助

2 个答案:

答案 0 :(得分:3)

如果您未在移动环境中运行该应用,则会收到此错误消息。

Select sum(total) as maintotal, sum(total) as subtotal, fmain 
from comparitive_st_sup 
where tender_id='$tender_id' 
group by ifmain, ifmain 

Uncaught ReferenceError: AdMob is not defined 是一个cordova插件。因此它会在chrome的控制台中显示错误。 为了避免这个错误。喜欢这个

admob

由于

答案 1 :(得分:1)

我做的最简单的事情就是从官方维基上获取this file的代码并粘贴到一个新文件中说admob.js;将admob.js包含到index.html和voilà中。

var admobid = {};

// TODO: replace the following ad units with your own
if( /(android)/i.test(navigator.userAgent) ) { 
  admobid = { // for Android
    banner: 'ca-app-pub-7545761285767751/5125248421',
    interstitial: 'ca-app-pub-7545761285767751/8299040824'
  };
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
  admobid = { // for iOS
    banner: 'ca-app-pub-7545761285767751/3766266425',
    interstitial: 'ca-app-pub-7545761285767751/9775774020'
  };
} else {
  admobid = { // for Windows Phone
    banner: 'ca-app-pub-7545761285767751/5205973626',
    interstitial: 'ca-app-pub-7545761285767751/6682706829'
  };
}

function initApp() {
  if (! AdMob ) { alert( 'admob plugin not ready' ); return; }

  // this will create a banner on startup
  AdMob.createBanner( {
    adId: admobid.banner,
    position: AdMob.AD_POSITION.BOTTOM_CENTER,
    isTesting: true, // TODO: remove this line when release
    overlap: false,
    offsetTopBar: false,
    bgColor: 'black'
  } );

  // this will load a full screen ad on startup
  AdMob.prepareInterstitial({
    adId: admobid.interstitial,
    isTesting: true, // TODO: remove this line when release
    autoShow: true
  });
}

if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
    document.addEventListener('deviceready', initApp, false);
} else {
    initApp();
}

由于AdMob未在浏览器中定义,但可以与模拟器或真实设备一起使用,因此请进行相应的测试。