首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用离子背景地理定位插件API完成?

如何使用离子背景地理定位插件API完成?
EN

Stack Overflow用户
提问于 2018-08-28 06:15:32
回答 1查看 293关注 0票数 1

我不太理解离子背景differences插件的API stop()和finish()之间的区别。作为下面的文档描述: finish()仅用于iOS。我是否需要总是将它添加到iOS应用程序的配置()函数中?

代码语言:javascript
复制
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation';

constructor(private backgroundGeolocation: BackgroundGeolocation) { }

...

const config: BackgroundGeolocationConfig = {
            desiredAccuracy: 10,
            stationaryRadius: 20,
            distanceFilter: 30,
            debug: true, //  enable this hear sounds for background-geolocation life-cycle.
            stopOnTerminate: false, // enable this to clear background location settings when the app terminates
    };

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

  });

// start recording location
this.backgroundGeolocation.start();

// If you wish to turn OFF background-tracking, call the #stop method.
this.backgroundGeolocation.stop();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-28 12:35:31

stop()函数

此函数将停止插件。就像开关一样。当用户禁用此功能或不再需要它时,您可以使用它。

finish()函数

此函数向OS指示任务(以获得当前位置)已完成。由于插件还在运行,它还会有其他类似的任务(直到下一次需要定位,也许几秒钟后)。对于每一项任务,您必须向操作系统指示任务何时完成。

如果没有这个函数调用,IOS将保持与插件的连接打开。因此,如文档中所示,对于IOS应用程序,您必须始终在这个插件中在回调函数中使用它。

如果我还不够清楚就告诉我。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52051250

复制
相关文章

相似问题

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