xcode iOS10如何跳转到系统设置的定位服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39940219/
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
How to jump to system setting's location service on iOS10?
提问by u6144118
Before I asked this question I had try:
在我问这个问题之前,我曾尝试过:
- Use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]];
It's work fine on iOS8 and iOS9,but there is nothing happen on iOS10. - Use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
It's work fine on iOS8 and iOS9,too.However,on iOS10,when the app jump to system setting, the system setting exit immediately. - Use
[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];
It's crashed on iOS8 and iOS9,also,exit immediately on iOS10.
- 使用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]];
它在 iOS8 和 iOS9 上工作正常,但在 iOS10 上没有任何反应。 - 使用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
在iOS8和iOS9上也可以正常使用。但是在iOS10上,当应用跳转到系统设置时,系统设置立即退出。 - 使用
[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];
它在iOS8和iOS9上崩溃,在iOS10上也立即退出。
The question is can our app jump to system setting on iOS10? If yes.How?And for [[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];
what's the options
means?We must code something for the options
?
问题是我们的app可以在iOS10上跳转到系统设置吗?如果是的话。[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];
怎么做options
?这意味着什么?我们必须为options
?
采纳答案by u6144118
Note:I use this method for a long time and everyting goes well,but today(2018-9-14),I had been rejected.
注意:我用这个方法很久了,一切都很好,但是今天(2018-9-14),我被拒绝了。
Here is my previous answer,do not use this method forever:
这是我之前的回答,永远不要使用这种方法:
CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (systemVersion < 10) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];
}else{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]
options:[NSDictionary dictionary]
completionHandler:nil];
}
Now I use this way:
现在我用这种方式:
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
回答by Paulw11
For some time now, apps have only been permitted to open their own settings pane in the settings app. There have been various settings URLs that have worked in the past, but recently Apple has been rejecting apps that use these URLS.
一段时间以来,只允许应用程序在设置应用程序中打开自己的设置窗格。过去有各种设置 URL 有效,但最近 Apple 一直拒绝使用这些 URL 的应用程序。
You can open your own application's settings:
您可以打开自己的应用程序设置:
if let url = URL(string:UIApplicationOpenSettingsURLString) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Or in Objective-C
或者在 Objective-C 中
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
[[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];
}
If you are targeting version of iOS earlier than 10 then you may prefer to use the older, deprecated, but still functional method:
如果您的目标是早于 10 的 iOS 版本,那么您可能更喜欢使用旧的、已弃用但仍然有效的方法:
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] openURL:url];
#pragma clang diagnostic pop
}
回答by Ayush Yadav
Note :- this solution will not be useful for ios10 onwards
注意:-此解决方案对 ios10 以后将无用
Dont forget to add URL schemes :-
不要忘记添加 URL 方案:-
Go to Project settings --> Info --> URL Types --> Add New URL Schemes-->URL Schemes = prefs
转到项目设置 --> 信息 --> URL 类型 --> 添加新的 URL Schemes-->URL Schemes = prefs
after that Use this url :-
之后使用这个网址:-
let settingUrl = URL(string: "App-Prefs:root=Privacy&path=LOCATION")
And open using :-
并打开使用:-
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingUrl) {
(isOpen:Bool) in
if !isOpen {
debugPrint("Error opening:\(settingUrl.absoluteString)")
// show error
}
}
}else{
if UIApplication.shared.canOpenURL(settingUrl) {
UIApplication.shared.open(settingUrl, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
}
}
Enjoy :)..this worked for me.
享受:)..这对我有用。
回答by yys
Thanks to this guy. I figure out this URL Scheme Prefs:root=Privacy&path=LOCATION
is only available in Today Widget, but no use in containing app.
多亏了这家伙。我发现这个 URL SchemePrefs:root=Privacy&path=LOCATION
只在 Today Widget 中可用,但在包含应用程序中没有用。
In Today Widget, you can try this:
在 Today Widget 中,你可以试试这个:
[self.extensionContext openURL:[NSURL URLWithString:@"Prefs:root=Privacy&path=LOCATION"] completionHandler:nil];
More about system URL Schemes, you can see here.
有关系统 URL Schemes 的更多信息,您可以在此处查看。
This all I got. Hope it will help you.
这都是我得到的。希望它会帮助你。
回答by sunkehappy
You can also open your app's setting center by opening"App-Prefs:root=your app bundle id"
. This will be easy for user to change setting for your app.
您也可以通过打开 来打开您应用的设置中心"App-Prefs:root=your app bundle id"
。这将便于用户更改您的应用程序的设置。
回答by NSKevin
This works for me. iOS7 ~ iOS11
这对我有用。iOS7 ~ iOS11
But if you are uing the iOS11, you can only jump to the app's setting page
但是如果你用的是iOS11,只能跳转到app的设置页面
NSURL *url1 = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"];
NSURL *url2 = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (@available(iOS 11.0, *)) {
if ([[UIApplication sharedApplication] canOpenURL:url2]){
[[UIApplication sharedApplication] openURL:url2 options:@{} completionHandler:nil];
}
} else {
if ([[UIApplication sharedApplication] canOpenURL:url1]){
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url1 options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:url1];
}
}
}