我正在尝试在我的应用程序中显示admob,但它没有显示在屏幕上。
我添加了它的插件: - cordova插件添加com.rjfun.cordova.plugin.admob cordova插件添加https://github.com/floatinghotpot/cordova-plugin-admob.git
这是我在运行函数下的app.js类中完成的代码: -
$ionicPlatform
.ready(function() {
if (window.plugins && window.plugins.AdMob) {
alert('inside');
var admob_key = device.platform == "Android" ? "ca-app-pub-6869992474017983/4748283957" : "IOS_PUBLISHER_KEY";
var admob = window.plugins.AdMob;
admob
.createBannerView({
'adId': admob_key,
'position': admob.AD_POSITION.BOTTOM_CENTER,
'adSize': admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function() {
admob
.requestAd({
'isTesting': false
},
function() {
admob
.showAd(true);
},
function() {
alert("failed to request ad");
console
.log('failed to request ad');
});
},
function() {
alert("failed to create banner view");
console
.log('failed to create banner view');
});
} else {
alert("AdMob plugin not available/ready.");
}
我从上面引用代码的链接: -
1)https://blog.nraboy.com/2014/06/using-admob-ionicframework/
2)https://github.com/floatinghotpot/cordova-admob-pro
请向我提出任何建议。
由于
答案 0 :(得分:2)
Admob的最新版本和nraboy在博客中的内容发生了一些变化。在我查看插件.js文件以查明更改之后,几周前我使用插件时发现了以下差异:
window.plugins.Admob
window.Admob
publisherId
下
adId
现在是bannerAtTop
position
现在是admob.createBannerView()
admob.createBanner()
现在只是admob.requestAd()
,在显示添加内容时,您可以完成所有工作(您无需拨打 if (window.AdMob) {
var admob = window.AdMob;
admob.createBanner({
adId: admob_key,
adSize: admob.AD_SIZE.SMART_BANNER,
position: admob.AD_POSITION.BOTTOM_CENTER,
isTesting: false, //Live
//isTesting: true, //Test
autoShow: true
}, function (data) {
console.log('Banner created... ' + angular.toJson(data));
}, function (err) {
console.log('Failed to create banner view... ' + angular.toJson(err));
});
} else {
//plugin not found
}
)等。要关注的模板
.AD_POSITION = {
NO_CHANGE: 0,
TOP_LEFT: 1,
TOP_CENTER: 2,
TOP_RIGHT: 3,
LEFT: 4,
CENTER: 5,
RIGHT: 6,
BOTTOM_LEFT: 7,
BOTTOM_CENTER: 8,
BOTTOM_RIGHT: 9,
POS_XY: 10
};
.AD_SIZE = {
SMART_BANNER: 'SMART_BANNER',
BANNER: 'BANNER',
MEDIUM_RECTANGLE: 'MEDIUM_RECTANGLE',
FULL_BANNER: 'FULL_BANNER',
LEADERBOARD: 'LEADERBOARD',
SKYSCRAPER: 'SKYSCRAPER'
};
其他信息
如果您不了解其他AD_SIZE和AD_POSITION选项(从插件.js文件复制)
App