我正在尝试为 ionic2 找到一些好的广告展示(视频)插件。我尝试过 https://github.com/cranberrygame/cordova-plugin-ad-adcolony但我无法调整它以与 ionic2 和 angular2 一起使用。我还审查了 AdMob ,它是 ionic2 插件,但不支持视频广告,正如我读到的那样(仅横幅)。您能否建议我对于我的 ionic2 应用程序应该使用什么以及如何使用。谢谢。
顺便说一句,当我尝试以这种方式运行 adcolony 时 window.plugins.adcolony.showIntersitialAd()
并使用下面的 HTML
<button ion-button (click)="window.plugins.adcolony.showInterstitialAd();">showInterstitialAd</button>
返回
HomePage.html:15 错误 TypeError: 无法读取未定义的属性“插件”
当我尝试像这样运行它时
<button ion-button (click)="window.adcolony.showInterstitialAd();">showInterstitialAd</button>
它返回以下错误:
HomePage.html:15 ERROR TypeError: Cannot read property 'adcolony' of undefined
任何帮助将不胜感激,谢谢:)
顺便说一句,我正在通过 https://apps.ionic.io/apps 测试该应用程序
最佳答案
尝试使用这个插件:https://github.com/appfeel/admob-google-cordova
cordova plugin add cordova-admob
请注意,您必须等待插页式广告加载,并且当您的应用程序在后台时禁用插页式广告也是一个好主意,因为您请求插页式广告的那一刻和显示它的那一刻之间存在延迟:
<button ion-button (click)="tryToShowInterstitial();">showInterstitialAd</button>
在你的 JavaScript 代码中:
var isAppForeground = true;
var isInterstitialAvailable = false;
function tryToShowInterstitial() {
if (isInterstitialAvailable) {
admob.showInterstitialAd();
} else {
// Do your button action here when there are no ads to show
}
}
function onAdLoaded(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialAvailable = true;
}
}
}
function onAdClosed(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
// Would you like to prepare next interstitial?
setTimeout(admob.requestInterstitialAd, 1);
isInterstitialAvailable = false;
}
}
}
function onPause() {
if (isAppForeground) {
admob.destroyBannerView();
isAppForeground = false;
}
}
function onResume() {
if (!isAppForeground) {
setTimeout(admob.createBannerView, 1);
setTimeout(admob.requestInterstitialAd, 1);
isAppForeground = true;
}
}
// optional, in case respond to events
function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdClosed, onAdClosed);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
}
function initAds() {
if (admob) {
var adPublisherIds = {
ios : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
},
android : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
}
};
var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
admob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
autoShowInterstitial: false
});
registerAdEvents();
} else {
alert('AdMobAds plugin not ready');
}
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
initAds();
// display a banner at startup
admob.createBannerView();
// request an interstitial
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);
关于javascript - Ionic 2 视频广告插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44879704/