allowDeferredLocationsUpdates在模拟器上工作,但不在我的iPhone 6s上

我想了解deferredLocationsfunction。 根据苹果文档,以下应该工作,而且当我在模拟器上运行它,但一旦我在我的iPhone 6s上安装应用程序,断开iPhone和运行应用程序,位置更新不会延迟。 我正在使用XCode 8和Swift 3。

这里是代码:

override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. locationManager=CLLocationManager() locationManager!.delegate=self locationManager!.desiredAccuracy=kCLLocationAccuracyBest locationManager!.requestAlwaysAuthorization() locationManager!.distanceFilter=kCLDistanceFilterNone locationManager!.allowsBackgroundLocationUpdates=true locationManager!.pausesLocationUpdatesAutomatically=false locationManager!.startUpdatingLocation() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if (!self.deferringUpdates) { locationManager!.allowDeferredLocationUpdates(untilTraveled: CLLocationDistanceMax, timeout: 60) self.deferringUpdates=true } } func locationManager(_ manager: CLLocationManager, didFinishDeferredUpdatesWithError error: Error?) { i=i+1 label.text="\(i)" print("didFinishDeferredUpdatesWithError") locationManager!.disallowDeferredLocationUpdates() self.deferringUpdates=false } 

我得到错误代码= 11,这是GPS不可用或类似的东西,每苹果文档。