背景地理位置不是 Observable
Background Geolocation isn't a Observable
我需要在我的应用程序中实施后台地理定位。我访问了这个 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
有人可以帮助我吗?
插件版本问题。在 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@3
我需要在我的应用程序中实施后台地理定位。我访问了这个 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
有人可以帮助我吗?
插件版本问题。在 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@3