Reputation: 179
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.
Upvotes: 0
Views: 1611
Reputation: 329
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.
Upvotes: 1
Reputation: 1874
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)
}
})
}
Upvotes: 0
Reputation: 1010
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.
Upvotes: 0
Reputation: 645
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.
*/
Upvotes: 2