xcode iOS 中的访问设置应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9664315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access Settings app in iOS
提问by MTSlive
Is there an opportinity to show up the settings.app in iOS by clicking on a button? It should work with iOS 5.1 so the "prefs:root..." url is no option.
是否有机会通过单击按钮在 iOS 中显示 settings.app?它应该适用于 iOS 5.1,所以“prefs:root...” url 是没有选择的。
Do you have an idea how to solve this?
你知道如何解决这个问题吗?
回答by djibouti33
I know the question is about 5.1 specifically, but in case anyone else is interested:
我知道这个问题特别是关于 5.1,但如果其他人有兴趣:
As of iOS 8, it is possible to take a user from your app directly into the Settings app. They will be deep linked into your app's specific Settings page, but they can back out into the top level Settings screen.
从 iOS 8 开始,可以将用户从您的应用程序直接带入设置应用程序。它们将深入链接到您应用程序的特定设置页面,但它们可以返回到顶级设置屏幕。
UPDATE:
更新:
Thanks to Pavel's comment, I simplified the if statement and avoided the EXC_BAD_ACCESS on iOS 7.
感谢 Pavel 的评论,我简化了 if 语句并避免了 iOS 7 上的 EXC_BAD_ACCESS。
UPDATE 2:
更新 2:
If your deployment target is set to 8.0 or above, Xcode 6.3 will give you the following warning:
如果你的部署目标设置为 8.0 或更高版本,Xcode 6.3 会给你以下警告:
Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true
This is because the feature was available starting in 8.0, so this pointer will never be NULL
. If your deployment target is 8.0+, just remove the if statement below.
这是因为该功能从 8.0 开始可用,因此该指针永远不会是NULL
. 如果您的部署目标是 8.0+,只需删除下面的 if 语句。
if (&UIApplicationOpenSettingsURLString != NULL) {
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
}
回答by Hailei
You are not able to do this on iOS 5.1. Most likely Apple removed that ability intentionally (you'll get "Please enter a valid URL", while Twitter can still call the Settings, though). Please refer to:
您无法在 iOS 5.1 上执行此操作。很可能 Apple 有意删除了该功能(您将收到“请输入有效的 URL”,但 Twitter 仍然可以调用设置)。请参阅:
回答by Banker Mittal
On iOS 8 Apple gave us the possibility to go to the App Settings right from our app
在 iOS 8 上,Apple 让我们可以直接从我们的应用程序转到应用程序设置
you can apply this code:
您可以应用此代码:
- (IBAction)openSettings:(id)sender {
BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
回答by Will Von Ullrich
The method openURL:
is now deprecated.
该方法openURL:
现已弃用。
iOS 10 +
iOS 10 +
The correct way to open the settings URL (or any URL for that matter) is as follows:
打开设置 URL(或与此相关的任何 URL)的正确方法如下:
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:^(BOOL success) {
// Do anything here
}];
回答by apostleofzion
iOS6 shows an option to open the settings app directly from an 'AlertView' (shown automatically) if it detects if you're trying to post to FB or Twitter without having those accounts setup.
如果 iOS6 检测到您是否在没有设置这些帐户的情况下尝试发布到 FB 或 Twitter,则它会显示一个选项,可以直接从“警报视图”(自动显示)打开设置应用程序。