我已经使用我的Ionic App实现了cordova-admob-pro插件。
我希望插页式广告在完成某个级别后显示,而不则在应用加载时显示。
这是我的代码:
app.js
// AdMob
if (window.plugins && window.plugins.AdMob && showAds) {
DebugService.add('admob OK');
if (window.plugins && window.plugins.AdMob) {
var admob_banner_key = device.platform == "Android" ? "ca-app-pub-7...6" : "ca-app-pub-7...0";
var admob_interstitial_key = device.platform == "Android" ? "ca-app-pub-7...5 " : "ca-app-pub-7...6";
var admob = window.plugins.AdMob;
admob.createBannerView(
{
'publisherId': admob_banner_key,
'adSize': admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function () {
admob.requestAd(
{'isTesting': true},
function () {
admob.showAd(true);
},
function () {
DebugService.add('failed to request ad');
}
);
},
function () {
DebugService.add('failed to create banner view');
}
);
admob.createInterstitialView(
{
'publisherId': admob_interstitial_key,
'autoShow': false
},
function() {
DebugService.add('interstitial successfully craeted');
},
function() {
DebugService.add('failed to add interstitial :-(');
}
);
}
}
controller.js:
if ($scope.levelId % 3 === 0) {
// after every second level and every third level after that
DebugService.add("Show interstitial ad :-)");
if ($localStorage.noAdsPurchased !== true &&
window.plugins && window.plugins.AdMob) {
DebugService.add('Ready to show interstitial');
window.plugins.AdMob.requestInterstitialAd(
{'isTesting': true},
function() {
window.plugins.AdMob.showInterstitialAd(true,
function(){
DebugService.add('interstitial successfully shown');
},
function(){
DebugService.add('interstitial show failed');
});
DebugService.add('interstitial successfully requested');
},
function() {
DebugService.add('failed to request interstitial');
}
);
DebugService.add('After showing interstitial');
}
}
插页式广告也会在开始时显示,我不想要。如果我删除代码或尝试将app.js中的代码仅用于控制器中的插页式广告,则插页式广告根本不显示。我在想,因为他们没有被发起。
如果没有在插播广告开头时展示插页式广告,我该如何发起插页式广告?
答案 0 :(得分:0)
感谢您的投入。这终于我解决了这个问题。
似乎只要调出createInterstitialView
方法,就会显示插页式广告。这就是它从一开始就表现出来的原因。
要解决此问题,我将所有AdMob代码移动到自己的服务中,并使用方法初始化,创建和展示广告。这样,在显示广告之前,系统不会调用createIntersititalView
。从控制器调用wwdWordRecognition.service('AdmobService', ['DebugService', function (DebugService) {
var _bannerId;
var _interstitialId;
var _isAdmobMissing = function() {
if(window.plugins === undefined || window.plugins.AdMob === undefined) {
return true;
}
return false;
};
this.init = function(bannerId, interstitialId) {
_bannerId = bannerId;
_interstitialId = interstitialId;
};
this.createAdmobBanner = function () {
if(_isAdmobMissing()) {
return false;
}
var _admob = window.plugins.AdMob;
_admob.createBannerView(
{
'publisherId': _bannerId,
'adSize': _admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function () {
_admob.requestAd(
{'isTesting': true},
function () {
_admob.showAd(true);
},
function () { DebugService.add('failed to request ad'); }
);
},
function () { DebugService.add('failed to create banner view');}
);
};
this.showInterstitial = function () {
if(_isAdmobMissing()) {
return false;
}
DebugService.add('Admob plugin found.');
var _admob = window.plugins.AdMob;
_admob.createInterstitialView(
{
'publisherId': _interstitialId
},
function () {
DebugService.add('interstitial successfully craeted');
_admob.requestInterstitialAd(
{'isTesting': true},
function() {
_admob.showInterstitialAd(true,
function(){ DebugService.add('interstitial successfully shown'); },
function(){ DebugService.add('interstitial show failed'); });
DebugService.add('interstitial successfully requested');
},
function() { DebugService.add('failed to request interstitial'); }
);
},
function () { DebugService.add('failed to add interstitial :-('); }
);
};
}]);
。
// AdMob
DebugService.add('Start ad setup...');
if (showAds) {
if (window.plugins && window.plugins.AdMob) {
var _admob_banner_key = device.platform == "Android" ? "ca-app-pub-7...6" : "ca-app-pub-7...0";
var _admob_interstitial_key = device.platform == "Android" ? "ca-app-pub-7...5 " : "ca-app-pub-7...6";
AdmobService.init(_admob_banner_key,_admob_interstitial_key);
AdmobService.createAdmobBanner();
} else {
DebugService.add('Admob plugin not found');
}
}
app.js现在看起来像这样:
if ($scope.listId % 3 === 0) {
// after every third list
DebugService.add("Show interstitial ad.");
if ($localStorage.noAdsPurchased !== true &&
window.plugins && window.plugins.AdMob) {
AdmobService.showInterstitial();
}
}
最后是controller.js:
ref