我有一个按钮,使用用户的位置搜索它们。如果他们尚未授予/拒绝使用其位置的权限,则会请求许可
相关代码:
func updateLocationStatus(){
locationEnabled = CLLocationManager.locationServicesEnabled()
appLocationEnabled = CLLocationManager.authorizationStatus()
}
@IBAction func searchNearby(sender: UIButton) {
updateLocationStatus()
if appLocationEnabled == CLAuthorizationStatus.Denied {
//Show an alert to let them know they've denied location permissions
presentViewController(alert, animated: true, completion: nil)
}
else if appLocationEnabled == CLAuthorizationStatus.NotDetermined ||
appLocationEnabled != CLAuthorizationStatus.AuthorizedWhenInUse &&
appLocationEnabled != CLAuthorizationStatus.AuthorizedAlways{
locationManager.requestWhenInUseAuthorization()
}
else{
activityIndicator.startAnimating()
locationManager.requestLocation()
}
}
正常使用时效果很好。但是,如果您让“允许应用程序使用您的位置[不允许] [允许]”警报在那里停留约5秒钟,则应用程序崩溃。该行跳转到Xcode导致错误
locationManager.requestWhenInUseAuthorization()
,提供的错误是
线程1:EXC_BAD_ACCESS(代码= 2,地址= 0xsomeaddress)
我甚至不知道从哪里开始解决这个问题,因为错误告诉我什么,功能完全正常,除非你什么都不做,