2017-04-16 14 views
0

このプラグインをIonic 2で使用すると、thereと表示され、src/app/app.components.tsの内部に追加されました。Ionic 2 Admob Plugin cordova-plugin-admob-free

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 {} 

エミュレータアプリケーションで試してみるとうまくいくが広告は出ない。私は何か悪いことをしていますか?

答えて

0

お試しください!

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); 
} 
}