admob with nativescript-vue integration



我正在尝试使用"nativescript-admob"将admob添加到我的应用程序中,这是我现在拥有的代码:

<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>

我尝试在"mounted"上启动AdMob,但我无法使其工作,有人以这种方式将AdMob与Nativescript-Vue集成吗? 就我而言,我什至没有看到日志"admob createBanner done"日志,所以也许我没有很好地使用这个插件。

admob.createBanner(( 函数必须被 setTimeout(( 包围才能启动,似乎必须在页面完全加载时启动。 感谢 Slack nativescript-vue 频道贡献者的帮助!

最新更新