我试图在一个应用程序中实现一个功能,当互联网连接不可用时显示警报。 警报有两个动作(确定和设置),每当用户单击设置,我想以编程方式将他们带到电话设置。
我使用Swift和Xcode。
我试图在一个应用程序中实现一个功能,当互联网连接不可用时显示警报。 警报有两个动作(确定和设置),每当用户单击设置,我想以编程方式将他们带到电话设置。
我使用Swift和Xcode。
当前回答
在iOS 10.3上,App-Specific URL Schemes的第一个响应对我来说很有效。
if let appSettings = URL(string: UIApplicationOpenSettingsURLString + Bundle.main.bundleIdentifier!) {
if UIApplication.shared.canOpenURL(appSettings) {
UIApplication.shared.open(appSettings)
}
}
其他回答
警告:prefs:root或App-Prefs:root URL方案被认为是私有API。如果你使用这些,苹果可能会拒绝你的应用,以下是你提交应用时可能会遇到的情况:
Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change. Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store. Next Steps To resolve this issue, please revise your app to provide the associated functionality using public APIs or remove the functionality using the "prefs:root" or "App-Prefs:root" URL scheme. If there are no alternatives for providing the functionality your app requires, you can file an enhancement request.
如上所述@niravdesai说App-prefs。 我发现App-Prefs:适用于iOS 9、10和11。设备测试。 where as prefs:仅适用于iOS 9。
我看过这行代码
UIApplication.sharedApplication() .openURL(NSURL(string:"prefs:root=General")!)
是不工作,它没有为我在ios10/ Xcode 8,只是一个小的代码差异,请替换这个
UIApplication.sharedApplication().openURL(NSURL(string:"App-Prefs:root=General")!)
Swift3
UIApplication.shared.openURL(URL(string:"prefs:root=General")!)
替换为
UIApplication.shared.openURL(URL(string:"App-Prefs:root=General")!)
希望能有所帮助。 欢呼。
App-Prefs:root=Privacy&path=LOCATION为我获得一般位置设置工作。注:仅在设备上有效。
在ios10/ Xcode 8模拟器:
UIApplication.shared.openURL(URL(string:UIApplicationOpenSettingsURLString)!)
作品
UIApplication.shared.openURL(URL(string:"prefs:root=General")!)
没有。