kev*_*ace 1 javascript android admob cordova
我正在尝试将 AdMob 广告放入我的 ionic android 应用程序中,并测试我制作的名为 AdMobTest 的 ionic 应用程序的功能。我使用的插件是cordova-admob-pro插件。这是我的 AdMob 代码:
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) { //Android
admobid = {
banner : 'ca-app-pub-2586564966169402/9782816366',
interstitial : 'ca-app-pub-2586564966169402/8345912938',
gotHereMsg1 : 'banner and interstitial have the android IDs'
};
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { //iOS
admobid = {
banner : 'Stand in iOS banner ID',
interstitial: 'stand in iOS interstitial ID',
gotHereMsg1 : 'banner and interstitial have the iOS IDs'
};
} else { //Neither
admobid = {
gotHereMsg1 : 'banner and interstitial have no IDs'
}
}
if (window.AdMob) {
var admob = window.AdMob;
admob.createBanner ({
adId : admobid.banner,
position : admob.AD_POSITION.BOTTOM_CENTER,
isTesting : false, //False for live ; True for production
autoShow : true
});
admob.prepareInterstitial ({
adId : admobid.interstitial,
autoShow : false
});
gotHereMsg2 = "window.AdMob is true";
} else {
gotHereMsg2 = "window.AdMob is not true";
}
//Got an ID and the actual ID's
document.getElementById("getIdCheck").innerHTML = admobid.gotHereMsg1;
document.getElementById("bannerId").innerHTML = admobid.banner;
document.getElementById("interstitialId").innerHTML = admobid.interstitial;
//window.AdMob is true and banner is created + interstitial is prepared
document.getElementById("isWindowAdmob").innerHTML = gotHereMsg2;
//Show interstitial function is executed or has not been executed
document.getElementById("startInterstitial").onclick = function () {
if (window.AdMob) {
var admob = window.AdMob;
admob.showInterstitial();
gotHereMsg3 = "Show Interstitial function has been executed";
} else {
gotHereMsg3 = "Show Interstitial function has not been executed";
}
document.getElementById("checkInterstitial").innerHTML = gotHereMsg3;
}
Run Code Online (Sandbox Code Playgroud)
为了展示我在使用“gotHereMsg”变量所做的测试中保留的内容。所有的变量都到达我想要的地方。
所以gotHereMsg1有关于android ID的消息并且ID也是正确的。
gotHereMsg2 返回“window.AdMob is true”,这意味着 createBanner 和prepareInterstitial 函数正在执行。
最后,当我单击按钮时,gotHereMsg3 返回“显示插页式函数已执行”。
尽管所有功能都在执行并且它显然可以识别 window.AdMob ,但没有显示任何横幅。希望这提供了足够的信息来解决这个问题。
值得注意的是,我使用的是 ionicv1,并且代码是在 ionic 的 app.js 文件中的 $ionicPlatform.ready 函数下编写的。
我对 admob 和 ionic v1 有丰富的经验。
首先,不要使用 cordova-admob-pro,他们(他?)确实从你那里窃取了收入!这里有大量的证据
if (window.admob !== undefined) {
admob.banner.config({
id: 'ca-app-pub-...',
autoShow: true
});
// Create banner
admob.banner.prepare();
// Show the banner
admob.banner.show();
admob.interstitial.config({
id: 'ca-app-pub-....',
autoShow: false
});
admob.interstitial.prepare();
}
Run Code Online (Sandbox Code Playgroud)
其次,我真的没有看到任何错误...我建议您在使用远程检查时在浏览器控制台窗口中运行 admob 命令...同时观察adb logcat是否出现“NO FILL” " 或任何其他 admob 错误
| 归档时间: |
|
| 查看次数: |
1347 次 |
| 最近记录: |