首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景地理位置不是可观测的

背景地理位置不是可观测的
EN

Stack Overflow用户
提问于 2019-01-31 09:12:41
回答 1查看 1.3K关注 0票数 0

我需要在我的应用程序中实现一个背景地理位置。我访问这个ionic documentation,这里显示了以下代码:

代码语言:javascript
复制
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。但当我运行时,显示以下错误:

代码语言:javascript
复制
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

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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中是错误的,因为那里说我们需要使用这个命令:

代码语言:javascript
复制
$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
$ npm install --save @ionic-native/background-geolocation@4

但我们需要使用此命令才能正常工作,并最终使用subscribe

代码语言:javascript
复制
$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@2.2.5
$ npm install --save @ionic-native/background-geolocation@3
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54451976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档