J'ai essayé d'ajouter des bannières publicitaires pour les nouvelles applications ionic 2, mais il affiche une erreur ci-dessous. je le fais comme indiqué ici tutorial . mais quand je le lance à partir du navigateur, en utilisant ionic serve -l -c
, il affiche l'erreur Runtime Error Cannot find module "ionic-native"
comme ci-dessous,
voici le code de monapp.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Geolocation } from '@ionic-native/geolocation';
import { AdMob } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { DetailsPage } from '../pages/details/details';
import { SettingModalPage } from '..Pages/setting-modal/setting-
modal';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(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();
let options = {
adId: 'ca-app-pub-5732334124058455/7973166445',
adSize: 'SMART_BANNER',
isTesting: false
};
AdMob.createBanner(options).then(() => {
AdMob.showBanner(8);
});
});
}
}
dans mon fichier package.json
,
"dependencies": {
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic-native/admob": "^3.4.4",
"@ionic-native/core": "^3.1.0",
"@ionic-native/geolocation": "^3.4.4",
"@ionic-native/launch-navigator": "^3.4.4",
"@ionic-native/splash-screen": "3.1.0",
"@ionic-native/status-bar": "3.1.0",
"@ionic/storage": "2.0.0",
"font-awesome": "^4.7.0",
"ionic-angular": "2.3.0",
"ionic2-rating": "^1.2.0",
"ionicons": "3.0.0",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.7.2"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.4",
"TypeScript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
Vérifiez ici .
import { AdMob } from 'ionic-native';
était en ionic-native 2.x
.
Faire:
ionic plugin add cordova-plugin-admobpro --save
npm install --save @ionic-native/admob
Et:
import { AdMob, AdMobOptions, AdSize, AdExtras} from '@ionic-native/admob';//import
constructor(platform: Platform, statusBar: StatusBar, splashScreen:
SplashScreen,admob:Admob)//inject in constructor.
//and use
let options:AdMobOptions={
adId: 'ca-app-pub-5732334124058455/7973166445',
adSize: 'SMART_BANNER',
isTesting: false
}
this.admob.createBanner(options).then(()=>{
this.admob.showBanner(8)
})
Le paquet ionic-native n'existe plus. Les modules sont maintenant dans son propre paquet, vous devez donc changer:
import { AdMob } from 'ionic-native';
de
import { AdMob } from '@ionic-native/admob';