Ionic 4 native plugin not working

我的梦境 提交于 2020-01-01 06:48:24

问题


I am facing a problem with Ionic 4 native plugins. I have installed ionic 4 Cordova native plugin "Geolocation" but when I run the app into my iOS or Android device it's showing to me a blank white screen and nothing happening.

app.module.ts code:

import {
  Geolocation
} from '@ionic-native/geolocation';
@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    ComponentsModule
  ],
  providers: [
    StatusBar,
    SplashScreen, ** Geolocation ** , {
      provide: RouteReuseStrategy,
      useClass: IonicRouteStrategy
    }
  ],
  bootstrap: [AppComponent]
})

Home.ts code:

import {
  Geolocation
} from '@ionic-native/geolocation';
constructor(private geolocation: Geolocation) {}

I don't know why it's happening. But It's working on Ionic 3 project.

Anyone can give me any idea why it's happening and what I did wrong.


回答1:


I've found the solution :

  • open your package.json and update @ionic-native/geolocation to 5.0.0-beta.14 (same as @ionic-native/core)
  • npm install
  • update all your imports : import {Geolocation} from '@ionic-native/geolocation/ngx'; (in app.module.ts and in your component.ts file)


来源:https://stackoverflow.com/questions/51626191/ionic-4-native-plugin-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!