【问题标题】:Ionic 2 Admob Plugin cordova-plugin-admob-freeIonic 2 Admob 插件 cordova-plugin-admob-free
【发布时间】:2017-04-16 17:18:48
【问题描述】:

我尝试在 Ionic 2 中使用这个插件,如 there 所示,并在 src/app/app.components.ts 中添加;

import { TabsPage } from '../pages/tabs/tabs';

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


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = TabsPage;

  constructor(private admobFree: AdMobFree,platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();


      const bannerConfig: AdMobFreeBannerConfig = {
         id: 'ca-app-pub-MYCODE',
         isTesting: true,
         autoShow: true
        };
      this.admobFree.banner.config(bannerConfig);
      this.admobFree.banner.show();  


    });
  }
}

喜欢那个代码。

我也导入模块,将提供程序添加到 src/app/app.module.ts ;

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

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

当我尝试在模拟器应用程序工作正常但没有广告。我做错了吗?

【问题讨论】:

    标签: android cordova typescript ionic2


    【解决方案1】:

    试试这个!

    constructor(private admobFree: AdMobFree) {
    this.showBannerAd(); //calling banner ads
    } 
    
    async showBannerAd(){
    
    try{
      const bannerConfig: AdMobFreeBannerConfig = {
        id : 'ca-app-pub-xxxx',
        isTesting : true,
        autoShow : true
      }
      this.admobFree.banner.config(bannerConfig);
      const result = await this.admobFree.banner.prepare();
      console.log('ad works fine', result);
    
    }
    
    catch(e){
      console.error(e);
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多