CLLocationManager.allowDeferredLocationUpdates在iOS 10上始终返回false

时间:2016-11-11 07:49:47

标签: ios swift core-location

我试图在我的全新iPhone 7和iOS 10.1.1上使用DeferredLocationUpdates,但它总是失败。

代码:

    locationManager.delegate = self
    locationManager.requestAlwaysAuthorization()
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.pausesLocationUpdatesAutomatically = true
    locationManager.activityType = .fitness
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.distanceFilter = kCLDistanceFilterNone
    locationManager.headingFilter = kCLHeadingFilterNone
    locationManager.startUpdatingLocation()

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    if !defersLocationUpdates {
        defersLocationUpdates = true
        locationManager.allowDeferredLocationUpdates(untilTraveled: CLLocationDistanceMax, timeout: CLTimeIntervalMax)
    }

}

CLLocationManager.deferredLocationUpdatesAvailable()始终返回false

0 个答案:

没有答案