我需要在我的应用程序中实现一个背景地理位置。我访问这个ionic documentation,这里显示了以下代码:
this.backgroundGeolocation.configure(config)
.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 HTTP request is 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
});当我在我的应用程序中使用这段代码时,我的ts-lint指责configure(config)方法是一个Promise<any>而不是Observable,所以,我不能使用subscribe。我把subscribe换成了then。但当我运行时,显示以下错误:
ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
at BackgroundGeolocation.configure (vendor.js:82333)
// error below ommited有人能帮我吗?
发布于 2019-02-01 19:12:26
问题出在插件版本上。在Ionic 3中,此版本运行良好:
config.xml文件:<plugin name="cordova-plugin-mauron85-background-geolocation" spec="^2.2.5" />
package.json文件:"@ionic-native/background-geolocation": "^3.14.0",
我在这个repository中找到了这个答案。
在Ionic v3 documentation中是错误的,因为那里说我们需要使用这个命令:
$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
$ npm install --save @ionic-native/background-geolocation@4但我们需要使用此命令才能正常工作,并最终使用subscribe
$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@2.2.5
$ npm install --save @ionic-native/background-geolocation@3https://stackoverflow.com/questions/54451976
复制相似问题