【发布时间】:2017-03-13 18:55:54
【问题描述】:
我制作了一个应用程序,当它进入后台时,我需要向服务器发送一些周期性数据。 为了从后台唤醒,我使用后台更新重要位置(电池电量较低)。 我注意到当手机从 wifi/3g 或 3g 更改手机信号塔时,位置会更新,但我的问题是,如果用户不移动(然后手机信号塔没有改变),位置不会更新并且应用无法唤醒,然后我无法向服务器发送数据。
你知道解决这个问题的方法吗?
我在 AppDelegate 文件中做所有这些:
class AppDelegate: UIResponder, UIApplicationDelegate , CLLocationManagerDelegate{
var manager = CLLocationManager()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.delegate = self
manager.requestAlwaysAuthorization()
manager.allowsBackgroundLocationUpdates = true
return true
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
sendDataToServer()
}
func applicationDidEnterBackground(_ application: UIApplication) {
manager.startMonitoringSignificantLocationChanges()
}
}
【问题讨论】:
-
你有没有得到合理的解决方案?
标签: ios swift background location