Mart
Mart

Reputation: 501

Phonegap admob not working in ios

I'm using phonegap to create an Android and iOS app, now i've added the admob plugin. (com.google.cordova.admob).

In android it works like it should but in iOS it won't work. My javascript code 'gets stuck' at the first time i pull AdMob.

document.addEventListener("deviceready", function(){
  startAds();
},true);

function startAds() {
        var admobid = {};
        alert(navigator.userAgent);
        if( /(android)/i.test(navigator.userAgent) ) { // for android

            admobid = {
                banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
                interstitial: 'ca-app-pub-xxx/zzz'
            };
        } else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios

            admobid = {
                banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
                interstitial: 'ca-app-pub-xxx/zzz'
            };
        } else { // for windows phone
            admobid = {
                banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
                interstitial: 'ca-app-pub-xxx/kkk'
            };
        }
        alert(4);
        if(AdMob) {
            alert(5);
            AdMob.createBanner( {
                adId: admobid.banner, 
                position: AdMob.AD_POSITION.BOTTOM_CENTER, 
                autoShow: true 
            } );
            alert(6);


            AdMob.prepareInterstitial( {adId:admobid.interstitial, autoShow:false} );
            alert(7);
        }
        alert(8);
    }

As you can see, i've added some alert functions to find where my code won't work. alert(4); is the last that works. alert(8) is not fired either.

What is going on, android works fine...

Upvotes: 1

Views: 307

Answers (1)

Mart
Mart

Reputation: 501

Oke, i have found the sollution:

add this line of code to your config.xml if you've got the same problem:

<gap:plugin name="com.google.cordova.admob" source="plugins.cordova.io"/>

Never had to do this before but it works now so.

Upvotes: 1

Related Questions