2017-07-03 4 views
0

Ich versuche ein gutes Plugin für die Anzeige zu finden (Videos) für ionic2. Ich habe mit https://github.com/cranberrygame/cordova-plugin-ad-adcolony versucht, aber ich kann es nicht anpassen, um mit ionic2 und angular2 zu arbeiten. Ich habe auch AdMob, das ionic2-Plugin, überprüft, aber Video-Anzeigen werden nicht unterstützt, wie ich gelesen habe (nur Banner). Kannst du mir bitte raten, was ich verwenden soll und wie, für meine ionic2 App. Vielen Dank.Ionic 2 video ad plugin

By the way, wenn ich versuche, auf diese Weise zu laufen AdColony window.plugins.adcolony.showIntersitialAd() mit dem HTML unter

<button ion-button (click)="window.plugins.adcolony.showInterstitialAd();">showInterstitialAd</button> 

es gibt

HomePage.html:15 ERROR TypeError: Cannot read property 'plugins' of undefined

und wenn ich versuche, es zu laufen so

<button ion-button (click)="window.adcolony.showInterstitialAd();">showInterstitialAd</button> 

es gibt die fo zurück llowing Fehler:

HomePage.html:15 ERROR TypeError: Cannot read property 'adcolony' of undefined 

jede Hilfe ist klar, danke :)

By the way, I`m Testen der App durch https://apps.ionic.io/apps

Antwort

1

Versuchen Sie, mit diesem Plugin: https://github.com/appfeel/admob-google-cordova

cordova plugin add cordova-admob 

Beachten Sie, dass Sie warten müssen, bis Interstitial geladen wird. Außerdem empfiehlt es sich, das Interstitial-Laden zu deaktivieren, wenn sich Ihre App im Hintergrund befindet , Da es eine Verzögerung zwischen dem Moment ist, dass Sie eine interstitielle und dem Moment fordern zeigen Sie es:

<button ion-button (click)="tryToShowInterstitial();">showInterstitialAd</button> 

Und in Ihrem Javascript-Code:

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

Hallo David, vielen Dank für Sie beantworten. Ich habe bereits AdMob in mein Projekt integriert, ich benutze Belohnungsvideo, aber das Problem ist, dass manchmal die Belohnung Videoanzeige nicht geladen wird :(Manchmal funktioniert perfekt, aber manchmal nicht geladen, haben Sie einen Vorschlag, warum dies passieren kann? ( –