简体   繁体   中英

ios11 didUpdateLocations not called

I'm developing ios app using CLLocationManager.

Until ios10, I called startUpdatingLocation, then didUpdateLocations is called, And I got a Location information.

Now, I update iOS11 beta9 and Xcode beta6. I called startUpdatingLocation, but didUpdateLocations was not called. So I cannot get any location.

Location is core information on my app. Is there anyone who got same problem? or can resolve this problem? sorry for my poor english. thank you.

In iOS 11 added new privacy key in info.plist, you should add any one of these, hope the addition in info.plist work for you.

/*
*      Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the
*      NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
*      keys must be specified in your Info.plist; otherwise, this method will do
*      nothing, as your app will be assumed not to support Always authorization.
*/

If you are running on simulator please make sure the simulator sets the location to custom location. By default it's select none. You can find it on simulator-> features -> locations It worked for me.

Add in Info.plsit

privacy - location usage description
Privacy - Location When In Use Usage Description
Application NSLocationAlwaysUsageDescription

在此处输入图片说明

   func CheckLocationAuthorization()  {
    if CLLocationManager.locationServicesEnabled() {
        switch CLLocationManager.authorizationStatus() {
        case .notDetermined, .restricted, .denied:
            self.ShowLocationError()
        case .authorizedAlways, .authorizedWhenInUse:
            // Do stuff
        }
    } else {
        self.ShowLocationError()
    }
}

//MARK:Show location error
func ShowLocationError()   {
    _ = UIAlertController.showAlertInViewController(viewController: self, withTitle: kAlertTitle, message: "Please allow location for getting the current weather report", cancelButtonTitle: "Setting", destructiveButtonTitle: nil, otherButtonTitles: nil, tapBlock: { (a, b, c) in
        if let url = URL(string:UIApplication.openSettingsURLString) {
            UIApplication.shared.open(url)
        }
    })
}

I had a different issue. I had accidentally declared the method as a class method instead of an instance method.

+ (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations

rather than

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations

Once I change the "+" to a "-", everything worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM