好吧,我知道有很多问题,但它们都来自很久以前。
所以。我知道这是可能的,因为地图应用程序可以做到这一点。
在地图应用程序中,如果我关闭此应用程序的本地化,它会向我发送一条消息,如果我按好,“设置应用程序”将打开。我的问题是,这怎么可能?如何从我自己的应用程序中打开“设置应用程序”?
基本上我需要做同样的事情,如果用户关闭我的应用程序的位置,那么我会给他一条消息,说明会打开“设置应用程序”
正如Karan Dua所提到的,这是使用now possible in iOS8的UIApplicationOpenSettingsURLString
,请参阅Apple's Documentation。
例:
Swift 4.2
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
在Swift 3中:
UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
在Swift 2中:
UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
在Objective-C中
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
在iOS 8之前:
你不能。正如你所说,这已被多次覆盖,并且弹出要求你打开位置服务是由Apple提供的,而不是由应用程序本身提供。这就是为什么它能够打开设置应用程序。
以下是一些相关的问题和文章:
is it possible to open Settings App using openURL?
Programmatically opening the settings app (iPhone)
How can I open the Settings app when the user presses a button?
iPhone: Opening Application Preferences Panel From App
Open UIPickerView by clicking on an entry in the app's preferences - How to?
SWIFT 4.0
在iOS 10.0中不推荐使用'openURL':请使用openURL:options:completionHandler:而不是
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
斯威夫特4
我更喜欢以更安全的方式打开设置,
UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)
Swift您可以使用以下功能打开带蓝牙页面的设置应用程序
if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {
UIApplication.shared.open(settingUrl)
}
else {
print("Setting URL invalid")
}
再次,这将无法打开应用程序的设置。这将打开蓝牙设置应用程序,因为这是深蓝色连接。
使用iOS 10测试。工作
func openSettingsApp(){
if let settings = NSURL(string: "prefs:root=Bluetooth") {
UIApplication.sharedApplication().openURL(settings)
}
}
快乐编码:)
把它添加到你的班级,
NSArray* urlStrings = @[@"prefs:root=WIFI", @"App-Prefs:root=WIFI"];
for(NSString* urlString in urlStrings){
NSURL* url = [NSURL URLWithString:urlString];
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
break;
}
}
像这样打电话,
public class func showSettingsAlert(title:String,message:String,onVC viewController:UIViewController,onCancel:(()->())?){
YourClass.show2ButtonsAlert(onVC: viewController, title: title, message: message, button1Title: "Settings", button2Title: "Cancel", onButton1Click: {
if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString){
UIApplication.sharedApplication().openURL(settingsURL)
}
}, onButton2Click: {
onCancel?()
})
}
public class func show2ButtonsAlert(onVC viewController:UIViewController,title:String,message:String,button1Title:String,button2Title:String,onButton1Click:(()->())?,onButton2Click:(()->())?){
dispatch_async(dispatch_get_main_queue()) {
let alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: button1Title, style:.Default, handler: { (action:UIAlertAction) in
onButton1Click?()
}))
alert.addAction(UIAlertAction(title: button2Title, style:.Default, handler: { (action:UIAlertAction) in
onButton2Click?()
}))
viewController.presentViewController(alert, animated: true, completion: nil)
}
}
您可以在iOS8中以编程方式打开设置应用程序,但不能在早期版本的iOS中打开。
迅速:
UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
斯威夫特4:
if let url = NSURL(string: UIApplicationOpenSettingsURLString) as URL? {
UIApplication.shared.openURL(url)
}
Swift 4.2(测试版):
if let url = NSURL(string: UIApplication.openSettingsURLString) as URL? {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Objective-C的:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
是!!您可以启动设备设置屏幕,我已在iOS 9.2上测试过
第1步。我们需要添加URL方案
转到项目设置 - >信息 - > URL类型 - >添加新URL方案
步骤2.以编程方式启动设置感谢@davidcann
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
我们也可以通过使用正确的名称来启动音乐,位置等子屏幕
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=MUSIC"]];
查看Henry Normal分享的全名列表qazxsw poi
更新:
根据评论,每个人都想知道在更改我的申请提交状态后会发生什么?
所以here
只是为了确认,我今天早上刚刚下载并禁用了位置服务,然后启动了应用程序,它询问了我的位置权限,然后我的警报弹出窗口就在那里发送设置 - >位置服务页面 - >已启用 - >而已!!
YES!! I got successful update submission and application is available on store without any complain.
![NOTICE:
Your app might be rejected ... even if it's approved it can be rejected in future version if you use this method...]
您可以在iOS 5.0及更高版本上使用它: 这不再有效。
4
iOS 10更新
Apple更改了在主线程上打开异步的方法。但是,从现在开始,只能在本机设置中打开应用程序设置。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
iOS 9更新
现在可以直接进入子设置菜单。但是,必须创建URL方案。它可以通过两种方式完成:
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
那么代码:
迅速
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>prefs</string>
</array>
</dict>
</array>
Objective-C的
UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=General&path=Keyboard")!)
在Swift 3 / iOS 10+中,现在看起来像
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Keyboard"]];
斯威夫特3:
if let url = URL(string: "App-Prefs:root=LOCATION_SERVICES") {
UIApplication.shared.open(url, completionHandler: .none)
}
在Swift 3中我只需要这个(这里例如重定向到我的应用程序通知):
guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(url)
}
资料来源:if let url = URL(string: "App-Prefs:root=NOTIFICATIONS_ID&path=your app bundleID") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, completionHandler: .none)
} else {
// Fallback on earlier versions
}
}
。
只有当设置在后台时,这才适用于我。它会将您重定向到您的应用通知设置,但如果设置未在后台运行,则只会将您重定向到通知设置。
phynet gist只有在您之前允许任何许可的情况下才能使用。例如,位置,照片,联系人,推送通知访问。因此,如果您没有来自用户的此类许可:
如果iOS 10或更高版本,
它将打开设置但随后崩溃。原因是,您的应用设置中没有任何内容。
下面的代码将在iOS设置中打开您的应用程序设置。
UIApplicationOpenSettingsURLString
由于设备不可用,我无法在iOS <10上查看此信息。
此外,我可以从一些要点找到下面的代码,它也适用于iOS 10。但我不确定这是否会得到Apple审核小组的批准。
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}