Ionic 4本机插件无法正常工作
问题描述:
我遇到了Ionic 4本机插件的问题.我已经安装了 ionic 4 Cordova本机插件 地理位置" ,但是当我在iOS或Android设备上运行该应用程序时,它却显示空白屏幕,但没有任何反应.
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
代码:
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
代码:
import {
Geolocation
} from '@ionic-native/geolocation';
constructor(private geolocation: Geolocation) {}
我不知道为什么会这样.但是它正在处理Ionic 3项目.
任何人都可以告诉我它为什么会发生以及我做错了什么.
Anyone can give me any idea why it's happening and what I did wrong.
答
我已经找到了解决方法:
I've found the solution :
- 打开您的 package.json 并将
@ionic-native/geolocation
更新为 5.0.0-beta.14 (与@ionic-native/core
相同) - npm安装
- 更新所有导入内容:
import {Geolocation} from '@ionic-native/geolocation/ngx';
(在app.module.ts和component.ts文件中)
- 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)