我正在使用CLLocationManager开发ios应用程序。
直到ios10,我调用了startUpdatingLocation,然后调用了didUpdateLocations,我得到了一个位置信息。
现在,我更新了iOS11 beta9和Xcode beta6。我调用了startUpdatingLocation,但没有调用didUpdateLocations。所以我找不到任何位置。
位置是我的应用程序的核心信息。有没有人有同样的问题?或者可以解决这个问题?对不起,我的英语很差。谢谢。
发布于 2017-09-06 15:04:38
在iOS 11中在info.plist中添加了新的私钥,你应该添加其中的任何一个,希望info.plist中的添加对你有用。
/*
* 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.
*/发布于 2020-12-12 01:29:27
如果您在模拟器上运行,请确保模拟器将位置设置为自定义位置。默认情况下,它是select none。你可以在模拟器-> features -> locations上找到它,它为我工作。
发布于 2017-09-06 17:57:59
在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)
}
})
}https://stackoverflow.com/questions/46068725
复制相似问题