一段时间以来,我一直在尝试编写代码以使Ionic的App构建不再那么久。像大多数用户一样,我使用
https://ionicframework.com/docs/native/background-geolocation编写代码。
此插件不起作用,我正在寻找不使用该插件的最佳方式。
我已经完成的工作使用了ionic 4本机文档中的代码完成,于2018年12月奏效。一段时间后,我今天打开了我的应用程序。应用程序崩溃了,我重新编写了代码。尝试了不同版本的插件,但无济于事,它们无法正常工作。
setBackgroundTracking(){
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your operations are successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
this.backgroundGeolocation.finish(); // FOR IOS ONLY
});
});
The above code is an exact copy paste from the documentation. and the code is buggy.
Property 'subscribe' does not exist on type 'Promise<any>'.ts(2339)
If you guys can fix the code or tell me another way to do it, please let me know. I have just been brainstorming would appreciate input/
答案 0 :(得分:1)
似乎您无法从文档中复制/粘贴:
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);