iPhone- 从我的应用程序 iOS 6 打开设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15682164/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:54:58  来源:igfitidea点击:

iPhone- Open Settings from my application iOS 6

iphoneiosobjective-c

提问by rohan-patel

I know there are many questions related to this.

我知道有很多与此相关的问题。

1) is it possible to open Settings App using openURL?

1)是否可以使用 openURL 打开设置应用程序?

2) Opening the Settings app from another app

2)从另一个应用程序打开设置应用程序

3) iOS Launching Settings -> Restrictions URL Scheme

3) iOS 启动设置 -> 限制 URL 方案

I have followed these questions for reference but that does not solve my query. I know that using openURLmethod you can open Settings but that was valid for only iOS 5.0 - 5.0.1. In iOS 5.1 it was deprecated.

我遵循了这些问题以供参考,但这并不能解决我的疑问。我知道使用openURL方法可以打开设置,但这仅对 iOS 5.0 - 5.0.1 有效。在 iOS 5.1 中它已被弃用。

  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]]; 

Still I have been seeing lot of Apps mainly location based which asks for user permission to turn on Location Services and takes directly to Location Servicesunder Settings--> Privacy.The screenshot of an App, which is installed on iOS 6.1 running device, below shows that tapping on Settings take you to directly Location Services.

我仍然看到很多主要基于位置的应用程序,它们要求用户允许打开定位服务并直接进入“设置”->“隐私”下的定位服务下面是一个安装在iOS 6.1运行设备上的App截图,点击设置可以直接进入定位服务

I tried to run code in my App but it is not working (I want to take user to Settings page to allow my app to access contact information directly from my App). If Apple has disabled URL Schemes for this how come many Apps are still using it?

我试图在我的应用程序中运行代码但它不起作用(我想将用户带到设置页面以允许我的应用程序直接从我的应用程序访问联系信息)。如果 Apple 为此禁用了 URL Schemes,那么为什么许多应用程序仍在使用它?

enter image description here

在此处输入图片说明

回答by Cocoadelica

For apps that tie into services such as Location, the first time they request access the OS will throw out the alert with buttons that link to Settings. This isn't actioned by the app, but by the underlying security of the OS.

对于与 Location 等服务相关联的应用程序,它们在第一次请求访问操作系统时会抛出带有链接到“设置”的按钮的警报。这不是由应用程序执行的,而是由操作系统的底层安全性执行的。

iOS 6 removed the ability to do this yourself as you mentioned.

正如您所提到的,iOS 6 删除了自己执行此操作的能力。

回答by Rajneesh071

You can open settings app programmatically in iOS8, but not in earlier versions of iOS.

您可以在 iOS8 中以编程方式打开设置应用程序,但不能在早期版本的 iOS 中打开。

In Swift:

在斯威夫特:

UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString));

Swift 4:

斯威夫特 4:

if let url = NSURL(string: UIApplicationOpenSettingsURLString) as URL? {
    UIApplication.shared.openURL(url)
}

In Objective-C

在 Objective-C 中

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];