gpt4 book ai didi

javascript - Cordova 在点击时显示 InterstitialAd

转载 作者:行者123 更新时间:2023-11-29 15:23:08 30 4
gpt4 key购买 nike

我正在使用 appfeel cordova admob 插件。 https://github.com/appfeel/admob-google-cordova

我想在我的 cordova 应用程序中显示 InterstitialAd on click 功能。通常使用默认选项,InterstitialAd 会在我的应用程序启动时显示。但必须在点击按钮时显示 InterstitialAd。

我的默认选项

admob.setOptions({
publisherId: "xxxx-myidxxx", // Required
interstitialAdId: "xxx-myidxxx", // Optional
tappxIdiOs: "/XXXXXXXXX/Pub-XXXX-iOS-IIII", // Optional
tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA", // Optional
tappxShare: 0.5,
adSize: admob.AD_SIZE.SMART_BANNER,
bannerAtTop: false,
overlap: false,
offsetStatusBar: false,
isTesting: true,
adExtras : {},
autoShowBanner: true,
autoShowInterstitial: false // Optional
});

我可以调用这种类型的函数

$( "#myButton" ).on( "click", function() {
admob.requestInterstitial();
admob.showInterstitialAd();
});

我正在尝试调用此类型的函数,但它不起作用。

点击按钮时如何调用函数?

最佳答案

请看这里:https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd ,有一个关于如何显示插页式广告的完整示例:

基本上您所做的是使用 autoShowInterstitial: false 启动广告,当设备准备就绪时使用 requestInterstitialAd,在发生点击事件时显示此预加载的插页式广告并重新加载新的插页式广告当显示最后一个时:

var isAppForeground = true;
var isInterstitialReady = true;

function onAdLoaded(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialReady = true;
}
}
}

function onAdClosed(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialReady = false;
admob.requestInterstitialAd();
}
}
}

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);

然后在你的按钮事件中:

$("#myButton").on( "click", function() {
if (isInterstitialReady) {
admob.showInterstitialAd();
} else {
// We do not have an interstitial ready, try to request a new one
// It can be mainly because of 3 reasons:
// - Can't connect with Admob (i.e. no connectivity available)
// - Admob does not have available any interstitials at this moment
// - Not enought time between last requestInterstitialAd() and myButton.click()
admob.requestInterstitialAd();
}
});

关于javascript - Cordova 在点击时显示 InterstitialAd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41919452/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com