[英]App crashes when requesting location and user does nothing
我有一个按钮,它使用用户的位置在他们周围搜索。 如果他们尚未授予/拒绝使用其位置的权限,它将请求该权限
相关代码:
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)
我什至不知道从哪里开始解决此问题,因为该错误告诉我什么也没有,并且该功能可以正常运行,除非您什么都不做太长时间
回溯提供任何有用的信息吗? 在控制台中,您可以在Xcode中断时在提示符下键入bt。 或者,您可以看一下调试导航器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.