Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

ios - How to jump to system setting's location service on iOS10?

Before I asked this question I had try:

  1. 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.
  2. 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.
  3. Use [[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];It's crashed on iOS8 and iOS9,also,exit immediately on 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 optionsmeans?We must code something for the options?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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:

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...