我正在尝试使用“ 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>
我尝试在“已挂载”上启动admob,但我无法使其正常工作,有人以这种方式将admob与nativescript-vue集成吗?就我而言,我什至没有看到“ admob createBanner done”日志,因此也许我不太好使用此插件。
答案 0 :(得分:2)
admob.createBanner()函数必须由setTimeout()包围才能在之后启动,似乎必须在页面完全加载时启动。 thx来帮助松弛的nativescript-vue渠道贡献者!