Vuejs2 admob与nativescript vue集成
我正在尝试使用“nativescript admob”将admob添加到我的应用程序中,以下是我目前拥有的代码:Vuejs2 admob与nativescript vue集成,vuejs2,admob,nativescript,nativescript-vue,Vuejs2,Admob,Nativescript,Nativescript Vue,我正在尝试使用“nativescript admob”将admob添加到我的应用程序中,以下是我目前拥有的代码: <template> <Page class="page"> <StackLayout class="hello-world"> <Label text="my home page"/> </StackLayout> </Page> </template> <scri
<template>
<Page class="page">
<StackLayout class="hello-world">
<Label text="my home page"/>
</StackLayout>
</Page>
</template>
<script>
const admob = require("nativescript-admob");
export default {
mounted() {
admob.createBanner({
// if this 'view' property is not set, the banner is overlayed on the current top most view
// view: ..,
testing: true, // set to false to get real banners
size: admob.AD_SIZE.SMART_BANNER, // anything in admob.AD_SIZE, like admob.AD_SIZE.SMART_BANNER
androidBannerId: "ca-app-pub-AAAAAAAAAAA/AAAAAAAAA", // add your own
margins: {
// if both are set, top wins
//top: 10
bottom: 50
},
}).then(
function() {
console.log("admob createBanner done");
},
function(error) {
console.log("admob createBanner error: " + error);
}
)
},
}
</script>
const admob=require(“nativescript admob”);
导出默认值{
安装的(){
admob.createBanner({
//如果未设置此“视图”属性,则横幅将覆盖在当前最上面的视图上
//观点:。。,
测试:true,//设置为false以获得真正的横幅
大小:admob.AD_size.SMART_BANNER,//任何具有admob.AD_大小的内容,如admob.AD_size.SMART_BANNER
androidBannerId:“ca-app-pub-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
利润:{
//如果两个都设置好了,top将获胜
//前10名
底数:50
},
}).那么(
函数(){
console.log(“admob createBanner done”);
},
函数(错误){
log(“admob createBanner错误:+错误”);
}
)
},
}
我尝试在“mounted”上启动admob,但我无法使其正常工作,有人以这种方式将admob与nativescript vue集成吗?在我的例子中,我甚至没有看到“admob createBanner done”日志,所以可能我没有很好地使用这个插件。admob.createBanner()函数必须被setTimeout()包围才能启动,它似乎必须在页面完全加载时启动。thx为slack nativescript vue频道贡献者提供帮助 请执行
npm干净运行
,然后重试。我这样做了,但仍然有一个错误:“admob createBanner错误:错误:java.lang.NullPointerException:尝试调用虚拟方法\'android.content.res.Resources android.content.Context.getResources()\'在空对象引用上如果执行tns调试
您将看到以下错误:admob.createBanner中的错误:TypeError:null不是对象(正在评估'utils.ios.getter(UIApplication,UIApplication.sharedApplication).keyWindow.rootViewController')“
如果只需要在加载页面时加载它,您可以将@loaded=“yourFunction”添加到页面标记中,并在加载页面元素时启动yourFunction。您应该能够在该函数中运行admob.createBanner()代码。如果它能工作,那就比依赖setTimeout()要好一点,因为加载元素的时间可能因设备而异。