iOS使用后台位置更新执行了LaunchWithOptions

时间:2018-06-15 20:25:12

标签: ios swift core-location

我有一个应用程序需要接收CoreLocation访问更新,只要系统在应用程序处于前台,后台或已终止时将其关闭。我在应用程序处于前台时使用UI开关启动跟踪。我也激活了后台定位功能。我相当可靠地在后台获取了访问信息,但是几天之后或者设备运行了很多其他的"重"应用程序似乎崩溃了。看起来我需要能够在系统将其杀死后重新启动应用程序。

class LocationService: NSObject, CLLocationManagerDelegate,UNUserNotificationCenterDelegate {

static let locationInstance = LocationService()
var locationManager = CLLocationManager()


func startTracking() {
    notifications()
    locationManager.delegate = LocationService.locationInstance
    locationManager.requestAlwaysAuthorization()
    locationManager.startMonitoringVisits()
    locationManager.allowsBackgroundLocationUpdates = true
}

即使在系统从后台终止应用程序后,我也无法弄清楚如何接收访问更新。我知道app delegate中的appDidFinishLaunchingWithOptions函数应该在后台激活,但我不确定: a)我已经设置了获取这些通知所需的一切 b)如果我收到通知,我不知道如何处理launchOptions字典。 c)我是否需要再次从app委托的didEnterBackground部分调用startMonitoringVisits()?

感谢您的任何见解!

0 个答案:

没有答案
相关问题