Admob Free - Ionic 2 - Angular 2

时间:2017-07-01 10:25:06

标签: angular ionic2 admob

我正在尝试使用Adonic 2和Angular 2的AdMob Free(cordova-plugin-admob-free),但我一直收到以下错误:

https://pastebin.com/Fj9b6cQc

要构建项目,我会执行以下操作:

  1. 离子cordova插件添加cordova-plugin-admob-free
  2. npm install --save @ ionic-native / admob-free
  3. 将此插件添加到您应用的模块
  4. 在app.module.ts

    import { AdMobFree } from '@ionic-native/admob-free';
    
    providers: [
        StatusBar,
        SplashScreen,
        {provide: ErrorHandler, useClass: IonicErrorHandler},
        AdMobFree
      ]
    
    1. 在home.ts

      import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';
      
        constructor(public navCtrl: NavController, private admobFree: AdMobFree)
      
    2. 在ngOnInit方法中:

      const bannerConfig: AdMobFreeBannerConfig = {
            // add your config here
            // for the sake of this example we will just use the test config
            isTesting: true,
            autoShow: true
            };
          this.admobFree.banner.config(bannerConfig);
      
          this.admobFree.banner.prepare()
            .then(() => {
              // banner Ad is ready
              // if we set autoShow to false, then we will need to call the show method here
            })
            .catch(e => console.log(e));
      

      有人可以帮助我吗?

      非常感谢!

      编辑:问题解决了!我没有更新SDK。对不起我的错:(

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

  let adId;
  if (this.platform.is('android')) {
    adId = 'ca-app-pub-xxxxxxxxxxx';

    var option: any = {
      adId: 'ca-app-pub-xxxxxxxxxxx',
      //size: 'SMART_BANNER',
      //position: admob.AD_POSITION.BOTTOM_CENTER,
      autoShow: true,
      isTesting: true,
    };
    console.log("option", option);
    this.admob.createBanner(option).then(() => {
      this.admob.showBanner(8);
    });

  } else if (this.platform.is('ios')) {
    adId = 'ca-app-pub-xxxxxxxxxxx';

    var option: any = {
      adId: 'ca-app-pub-xxxxxxxxxxx',
      //size: 'SMART_BANNER',
      //position: admob.AD_POSITION.BOTTOM_CENTER,
      autoShow: true,
      isTesting: true,
    };
    console.log("option", option);
    this.admob.createBanner(option).then(() => {
      this.admob.showBanner(8);
    });
  }
  this.admobFree.banner.prepare()
    .then(() => { this.admobFree.banner.show(); });