How to implement Admob into Ionic?

后端 未结 2 450
无人共我
无人共我 2021-01-24 15:46

I followed the instructions of this post: AdMob not loading ads in ionic/angular app

When I run the app via \"ionic build ios && ionic emulate ios\" I get no ads

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 16:26

    Follow these steps:

    1. ionic platform add android ionic platform add ios
    2. cordova plugin add com.rjfun.cordova.plugin.admob
    3. Paste these code in run module of app.js's

    code:

    $ionicPlatform.ready(function() {
        if(window.plugins && window.plugins.AdMob) {
            var admob_key = device.platform == "Android" ? "ANDROID_PUBLISHER_KEY" : "IOS_PUBLISHER_KEY";
            var admob = window.plugins.AdMob;
            admob.createBannerView( {
                'publisherId': admob_key,
                'adSize': admob.AD_SIZE.BANNER,
                'bannerAtTop': false
            }, 
            function() {
                admob.requestAd({ 'isTesting': false }, 
            function() {
                admob.showAd(true);
            }, 
            function() { console.log('failed to request ad'); });
            }, 
            function() { console.log('failed to create banner view'); });
        }
    });
    

    Regards.

提交回复
热议问题