【发布时间】:2017-05-17 23:43:15
【问题描述】:
如果之前访问被拒绝,我对于访问设置以启用设备功能的最佳方式有点困惑。我已经看到了两种方法,其中一种似乎正在使用线程。但是我还没有找到一个明确的解释为什么?对此有任何见解。谢谢。
两者都有效,或者下面的 sn-p 作为警报控制器的操作:
alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: {(_ action: UIAlertAction) -> Void in
//open settings to allow access to geo
guard let stngUrl = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(stngUrl) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(stngUrl, completionHandler: { (success) in
})
} else {
if UIApplication.shared.canOpenURL(stngUrl) {
UIApplication.shared.openURL(stngUrl)
}
}
}
}))
present(alert, animated: true, completion: nil)
或使用 DispatchQueue 像下面的 sn-p?
alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: {(_ action: UIAlertAction) -> Void in
DispatchQueue.main.async(execute: {() -> Void in
UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
})
}))
present(alert, animated: true, completion: nil)
【问题讨论】:
标签: ios swift permissions privacy