我希望 func locationManager(manager: CLLocationManager, didUpdateToLocation 即使在应用程序被杀死后也能被调用?

Posted

技术标签:

【中文标题】我希望 func locationManager(manager: CLLocationManager, didUpdateToLocation 即使在应用程序被杀死后也能被调用?【英文标题】:I want func locationManager(manager: CLLocationManager, didUpdateToLocation to be called even after app is killed? 【发布时间】:2016-11-07 12:51:56 【问题描述】:

在我的应用程序被杀死后,我想根据 location.speed 参数重新启动应用程序,我的意思是说当设备速度>5kmph 时,我希望我的应用程序能够打开并且需要以编程方式单击一个按钮?

【问题讨论】:

在有限的场景中可以在后台使用核心位置。你应该看看documentation 【参考方案1】:

不可能。

当你的进程被杀死时,你不能执行部分代码。就这么简单。

您可以在 android 中使用后台服务执行此操作,即使您的应用程序因后台服务是不同的进程而被终止,该服务也会运行。但是ios不允许创建后台服务。

【讨论】:

【参考方案2】:

设置allowBackgroundLocationUpdates = true

allowBackgroundLocationUpdates 的默认值为 NO

如果您的应用在后台使用位置(不显示蓝色状态栏),除了在 Info.plist 中设置后台模式功能外,您还必须将 allowBackgroundLocationUpdates 设置为 YES。否则位置更新仅在前台传递。优点是您现在可以在同一应用程序中拥有具有后台位置更新的位置管理器和仅具有前台位置更新的其他位置管理器。您还可以将该值重置为 NO 以更改行为。

【讨论】:

这将在应用程序处于后台时执行。我需要在应用程序被杀死(终止后)后调用 CLLocation 管理器 didUpdateLocations 的委托方法 set allowedBackgroundLocationUpdates = YES 。检查这是否解决了您的问题。 您给出的答案是应用在后台时。但我的问题是当应用程序被杀死时,我需要频繁调用 didUpdateLocations 方法并运行。 那么不可能:|

以上是关于我希望 func locationManager(manager: CLLocationManager, didUpdateToLocation 即使在应用程序被杀死后也能被调用?的主要内容,如果未能解决你的问题,请参考以下文章

未从 LocationManager 中清除的 Android 模拟位置提供程序

我应该在 locationManager:didFailWithError: 中发送 [locationManager stopUpdatingLocation] 吗?

我如何知道LocationManager GPS检索的提供者?

locationManager.getLastKnownLocation() 返回 null

locationManager.location 返回 nil

CoreLocation:LocationManager.stopUpdatingLocation() 不工作