CoreLocation和后台URL请求

时间:2019-07-19 09:54:26

标签: swift core-location ios-background-mode

我需要跟踪用户位置,并且即使用户未使用该应用程序,每个x米也会发送一个http请求。

我将CLLocationManager设置为requestAlwaysAuthorization(),然后按照in the docs的描述实施委托。

func locationManager(_ manager: CLLocationManager,  didUpdateLocations locations: [CLLocation]) {
    let lastLocation = locations.last!

    // send URL request here

}

当应用程序处于前台时,我可以简单地发送http请求。

现在的问题是,当用户将应用程序置于后台时,正确的处理方法是什么?当我使用requestAlwaysAuthorization请求位置时,我仍将获得位置更新,但是可以发送http请求吗?我可以使用beginBackgroundTaskWithExpirationHandler吗?还是该应用始终保持active的位置,因此不需要使用beginBackgroundTaskWithExpirationHandler

0 个答案:

没有答案