IONIC 3-即使将isTesting设置为true,AdMob Free也不起作用

时间:2018-10-08 09:06:46

标签: ionic-framework ionic3 admob cordova-admob

我试图从最近3天开始在Ionic 3应用程序中运行Google AdMob。 我遵循的步骤:

1。。创建的Ionic 3 App添加了AdMob Free。

2。。要检查我的AdMob帐户是否停止了广告,请创建一个本机android示例应用,其中该横幅广告开始实时显示。真实广告,而非测试。

3。。创建一个新的Ionic 3示例应用程序,但仍然没有成功。

有人面临类似问题吗??请帮助让我知道是否还有遗忘的地方。

我遵循了一个here的教程

这是我的代码:

安装了这些软件包:

cordova plugin add cordova-plugin-admob-free --save
npm install @ionic-native/admob-free --save

app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
    import { ErrorHandler, NgModule } from '@angular/core';
    import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { StatusBar } from '@ionic-native/status-bar';

    import { AdMobFree } from '@ionic-native/admob-free';

    import { MyApp } from './app.component';
    import { HomePage } from '../pages/home/home';



    @NgModule({
      declarations: [
        MyApp,
        HomePage
      ],
      imports: [
        BrowserModule,
        IonicModule.forRoot(MyApp)
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp,
        HomePage
      ],
      providers: [
        StatusBar,
        SplashScreen,
        AdMobFree,
        {provide: ErrorHandler, useClass: IonicErrorHandler}
      ]
    })
    export class AppModule {}

home.ts

    import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    import { AdMobFree, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig, AdMobFreeRewardVideoConfig } from '@ionic-native/admob-free';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })
    export class HomePage {

      constructor(public navCtrl: NavController,public admobFree: AdMobFree) {

      }

      showBannerAd() {

          let bannerConfig: AdMobFreeBannerConfig = {
              isTesting: true, // Remove in production
              autoShow: true//,
              //id: "ca-app-pub-3940256099942544/6300978111"
          };
          this.admobFree.banner.config(bannerConfig);

          this.admobFree.banner.prepare().then(() => {
              alert("bannerConfig");
          }).catch(e => alert(e));
      }



      showInterstitialAds(){
          let interstitialConfig: AdMobFreeInterstitialConfig = {
              isTesting: true, // Remove in production
              autoShow: true//,
              //id: "ca-app-pub-3940256099942544/1033173712"
          };
          this.admobFree.interstitial.config(interstitialConfig);
          this.admobFree.interstitial.prepare().then(() => {
            alert("interstitialConfig");
          }).catch(e => alert(e));
      }

      showRewardVideoAds(){
          let RewardVideoConfig: AdMobFreeRewardVideoConfig = {
              isTesting: true, // Remove in production
              autoShow: true//,
              //id: "ca-app-pub-3940256099942544/5224354917"
          };
          this.admobFree.rewardVideo.config(RewardVideoConfig);
          this.admobFree.rewardVideo.prepare().then(() => {
            alert("RewardVideoConfig");
          }).catch(e => alert(e));
      }


    }

home.html

    <ion-header>
      <ion-navbar>
        <ion-title>
          Ionic Blank
        </ion-title>
      </ion-navbar>
    </ion-header>

    <ion-content padding>
      The world is your oyster.
      <p>
        If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
      </p>

      <button ion-button (click)="showBannerAd()">showBannerAd</button>
      <button ion-button (click)="showInterstitialAds()">showInterstitialAds</button>
      <button ion-button (click)="showRewardVideoAds()">showRewardVideoAds</button>
    </ion-content>

更新:终于!广告正在展示。可能需要2-3天。:)

2 个答案:

答案 0 :(得分:1)

只需在命令行中尝试此操作(将您的应用ID放在“”之间):

  

cordova插件添加了cordova-plugin-admob-free --save --variable ADMOB_APP_ID =“ YOUR_APP_ID

示例:

  

cordova插件添加了cordova-plugin-admob-free --save --variable ADMOB_APP_ID =“ ca-app-pub-90001987983570300〜8789081597”

答案 1 :(得分:0)

确保仅在仿真器中对其进行测试,否则您将得到未安装插件的错误。