【发布时间】:2016-11-23 03:41:25
【问题描述】:
我有一个功能,我想在应用程序后台模式下运行,并且至少每分钟执行一次,以检查 wifi 连接并做出决定。我正在使用 locationManager 委托,所以我可以在后台运行我的 NSTimer。然而,位置管理器消耗了大量的电池电量。此应用程序不适用于 Apple 版本。但是,我正在为位置管理器寻找更有效的设置,这样它就不会那么耗电或任何其他好主意? 我的当前设置还可以,但是由于我为位置管理器启用了自动暂停,因此功能更新延迟太多。在我使用两个委托方法(didEnterRegion 和 didExitRegion)之前,这些方法更耗电且不准确。我阅读了大量可用的教程并检查了有关堆栈溢出的其他相关帖子,但没有找到任何可以帮助我解决问题的内容 这是我的委托函数中的内容:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.timer = NSTimer.scheduledTimerWithTimeInterval(45, target: self, selector: #selector(self.checkNetworkSSID), userInfo: nil, repeats: true)
manager.stopMonitoringSignificantLocationChanges()
manager.stopUpdatingLocation()
}
这是我的 viewDidLoad 和 AppDelegate
中的内容manager = CLLocationManager()
manager?.delegate = self
manager?.requestWhenInUseAuthorization()
manager?.startUpdatingLocation()
manager?.desiredAccuracy = kCLLocationAccuracyThreeKilometers
manager?.pausesLocationUpdatesAutomatically = true
manager?.activityType = CLActivityType.Fitness
【问题讨论】:
标签: swift location nstimer core-location background-process