Meteor应用程式未定义AdMob [英] AdMob is not defined on Meteor app
问题描述
我有Meteor(v1.0.3.1)应用程式并安装了AdMob Cordova插件,例如:
meteor add cordova :com.google.cordova.admob@https://github.com/floatinghotpot/cordova-admob-pro/tarball/94a31660d1bb35337e3430e2608b7710ea4d882a
使用以下代码作为文档建议:
if(Meteor.isCordova){
admobid = {
banner:'ca-app-pub-xxxxxxxxxxxxxxxxxxx'
};
if(AdMob){
AdMob.createBanner({
adId:admobid.banner,
position:AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow: true
});
}
}
堆栈跟踪中出现以下错误:
$ b $ 未捕获的引用错误:未定义AdMob
我在窗口和其他地方寻找AdMob对象,但找不到它。
插件你正在使用是工作。但你可能不应该使用tarball。改用当前版本(2.7.4)。
试试这个。
- 删除您安装的插件
meteor remove
-
使用版本号安装
meteor add cordova:com.google.cordova .admob @ 2.7.4
-
运行simluator(如果没有Xcode, >
meteor run ios
然后,AdMob变量应该可用。
插件也可以适用于Android。
`流星运行android'
此外,请确保您的代码位于 Meteor.startup()
中,以确保Cordova插件可用。 / p>
Meteor.startup(function(){
if(Meteor.isCordova){
if(AdMob) {
AdMob.createBanner({
adId:'ca-app-pub-3080070244198226/2109901818',
position:AdMob.AD_POSITION.BOTTOM_CENTER,
isTesting:true,
autoShow:true,
success:function(){
console.log(Received ad);
},
error:function(){
console.log(No ad received);
}
});
} else {
console.log(No Admob);
}
} else {
console.log(No Cordova);
}
}
I have a Meteor(v1.0.3.1) app and installed AdMob Cordova plugin like this:
meteor add cordova:com.google.cordova.admob@https://github.com/floatinghotpot/cordova-admob-pro/tarball/94a31660d1bb35337e3430e2608b7710ea4d882a
with the following code as the doc suggests:
if(Meteor.isCordova){
admobid = {
banner: 'ca-app-pub-xxxxxxxxxxxxxxxxxxx'
};
if(AdMob){
AdMob.createBanner( {
adId: admobid.banner,
position: AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow: true
});
}
}
And started the app with meteor run android-device
with my Android phone plugged in.
The following error appears in the stack trace:
Uncaught ReferenceError: AdMob is not defined
I looked for AdMob object on window and other places but couldn't find it.
I can confirm that the plugin you are using is working. But you should probably not use the tarball. Use the current version (2.7.4) instead.
Try this. This worked for me using the iOS simulator.
- Remove the plugin you installed with
meteor remove
Install with version number
meteor add cordova:com.google.cordova.admob@2.7.4
Run the simluator (use the Android one, if you do not have Xcode )
meteor run ios
Then the AdMob variable should be available. At least it was when I tried it.
Update
The plugin also works with Android.
`meteor run android`
Also, make sure that your code is in Meteor.startup()
, to ensure that the Cordova plugin is available.
Meteor.startup(function () {
if (Meteor.isCordova) {
if (AdMob) {
AdMob.createBanner( {
adId: 'ca-app-pub-3080070244198226/2109901818',
position: AdMob.AD_POSITION.BOTTOM_CENTER,
isTesting: true,
autoShow: true,
success: function() {
console.log("Received ad");
},
error: function() {
console.log("No ad received");
}
});
} else {
console.log("No Admob");
}
} else {
console.log("No Cordova ");
}
}
这篇关于Meteor应用程式未定义AdMob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!