0

所以在我的 ionic 项目中,我试图加载插页式广告,但我的模拟器设备中没有显示,我从 applovin 文档cordova中选择了代码,我还在 gradle 文件中集成了他们问我的内容,当然我做到了插件。我想知道 Ionic 是否不接受这种方式,或者我应该将其转换为打字稿。我将此代码放在 home.page.ts 中,当单击某个按钮时调用插页式广告。

declare var window: any;
declare var cordova: any;
declare var bannerAdUnitId: any;
var AppLovinMAX = cordova.require('cordova-plugin-applovin-max.AppLovinMAX');


AppLovinMAX.initialize("RAfucl4TfsPn8kt_iKFCoFsaI59861MbWMxU6W_6JIV6eHL42gFPgE6xps14lF00MfnHNCOenKVfPKV8vf7IqN", function (configuration) {
    // SDK is initialized, start loading ads
});

var INTER_AD_UNIT_ID;
if (window.cordova.platformId.toUpperCase() === 'IOS') {
    INTER_AD_UNIT_ID = 'YOUR_IOS_INTER_AD_UNIT_ID';
} else {
    // Assume Android
    INTER_AD_UNIT_ID = '';
}

var retryAttempt = 0;

function initializeInterstitialAds()
{
    window.addEventListener('OnInterstitialLoadedEvent', function (adInfo) {
        // Interstitial ad is ready to be shown. AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID) will now return 'true'
        
        // Reset retry attempt
        retryAttempt = 0;
    });

    window.addEventListener('OnInterstitialLoadFailedEvent', function (adInfo) {
        // Interstitial ad failed to load 
        // We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds)
    
        retryAttempt++; 
        var retryDelay = Math.pow(2, Math.min(6, retryAttempt));

        console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's');
          
        setTimeout(function() {
            loadInterstitial();
        }, retryDelay * 1000);
    });

    window.addEventListener('OnInterstitialClickedEvent', function (adInfo) {});
    window.addEventListener('OnInterstitialDisplayedEvent', function (adInfo) {});
    window.addEventListener('OnInterstitialAdFailedToDisplayEvent', function (adInfo) {
        // Interstitial ad failed to display. We recommend loading the next ad
        loadInterstitial();
    });
    window.addEventListener('OnInterstitialHiddenEvent', function (adInfo) {
        loadInterstitial();
    });

    // Load the first interstitial
    loadInterstitial();
}

function loadInterstitial()
{
    AppLovinMAX.loadInterstitial(INTER_AD_UNIT_ID);
}

if (AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID))
{
    AppLovinMAX.showInterstitial(INTER_AD_UNIT_ID);
}
4

0 回答 0