【发布时间】:2018-05-24 12:16:54
【问题描述】:
在我获取用户位置的函数中,我创建了预权限,以便在授权消息之前发出警报,以免失去从用户那里获得必要权限的 1 机会。
func getCurrentLocation() {
// Init LocationManager
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy =
kCLLocationAccuracyThreeKilometers;
let alert = UIAlertController(title: "Allow Loction Services?",
message: "This allows the app to your loction",
preferredStyle: .alert)
let ok = UIAlertAction(title: "Allow", style: .default, handler: {
(action) -> Void in
self.showHUD("loading...")
if locationManager.responds(to:
#selector(CLLocationManager.requestWhenInUseAuthorization)) {
locationManager.requestAlwaysAuthorization()
}}
self.hideHUD()
)
}
let cancel = UIAlertAction(title: "Not Now", style: .destructive,
handler: { (action) -> Void in })
alert.addAction(ok); alert.addAction(cancel)
present(alert, animated: true, completion: nil)
locationManager.startUpdatingLocation()
}
在该部分:
let ok = UIAlertAction(title: "Allow", style: .default, handler: {
(action) -> Void in
self.showHUD("loading...")
一个错误提示我们“表达式类型不明确,没有更多上下文”
【问题讨论】:
标签: swift xcode permissions cllocationmanager uialertcontroller