我想在iOS 11中使用Swift 4在“设置”应用内打开我的应用设置页面。如图所示:
以下代码无效,只会打开“设置”应用:
if let url = URL(string:UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
上图中的应用程序显示能够做到这一点。所以我想知道是否有任何方法可以自定义URL Scheme来实现它?
答案 0 :(得分:3)
糟糕,它似乎可以在iOS 11.4.1中运行:
if let url = URL(string:UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
答案 1 :(得分:2)
对于 Swift 5 :
func goToAppSettings() {
if let url = URL(string: UIApplication.openSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
答案 2 :(得分:0)
只是更新,因为UIApplicationOpenSettingsURLString发生了更改。
guard let url = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}