如何使用 ionic backgroundgeolocation 插件 API 完成?

how to use ionic backgroundgeolocation plugin API finish?

我不太明白 ionic backgroundgeoloaction 插件的 API stop() 和 finish() 之间的区别。如下面的文档描述:finish() 仅用于 iOS。我是否需要始终将它添加到 iOS 应用程序的 configure() 函数中?

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();

stop() 函数

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

finish() 函数

此函数向 OS 指示任务(获取当前位置)已完成。由于插件仍然是 运行,它稍后会有其他类似的任务(直到下一次它需要定位,可能是几秒钟后)。对于每项任务,您必须向 OS 表明任务已完成,何时完成。

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

如果我不够清楚,请告诉我。