微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当应用程序被用户杀死时如何重新启动位置更新?

如何解决当应用程序被用户杀死时如何重新启动位置更新?

即使应用程序在后台,我也在尝试获取用户位置。

该应用程序也始终具有位置权限。

应用在后台运行良好,但当用户杀死应用时,它不起作用。

我正在使用这个 startMonitoringSignificantLocationChanges获取位置

locationManager?.startMonitoringSignificantLocationChanges()
locationManager?.allowsBackgroundLocationUpdates = true

但手机重启后,即使应用程序没有运行,位置更新也有效。 只有当应用程序被用户在任务中杀死时,它才不起作用。

func applicationDidEnterBackground(_ application: UIApplication) {
        Log.debug("Did Enter Background")
        self.locationManager?.stopMonitoringSignificantLocationChanges()
        self.locationManager           = CLLocationManager()
        self.locationManager?.delegate = self
        self.locationManager?.requestAlwaysAuthorization()
        self.locationManager?.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager?.distanceFilter = 500
        self.locationManager?.activityType = CLActivityType.otherNavigation
        self.locationManager!.allowsBackgroundLocationUpdates = true
        self.locationManager?.pausesLocationUpdatesAutomatically = false
        self.locationManager?.startMonitoringSignificantLocationChanges()
}

解决方法

我刚刚通过使用 allowDeferredLocationUpdates

解决了这个问题
days = ['mon','tue','wed','thu','fri','sat','sun']
grouped = sleep.groupby('day_of_week')
groups = {days[i]: grouped.get_group(i).loc[:,'df'] for i in range(len(days))}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。