好吧,我知道关于它有很多问题,但它们都是很久以前的事了。

所以。我知道这是可能的,因为地图应用程序做到了。

在地图应用程序中,如果我关闭这个应用程序的本地化,它会给我发送一条消息,如果我按ok,“设置应用程序”就会打开。 我的问题是,这怎么可能呢? 如何从我自己的应用程序打开“设置应用程序”?

基本上我需要做同样的事情,如果用户关闭了我的应用程序的位置,那么我就会给他显示一条信息,上面写着将打开“设置应用程序”


当前回答

斯威夫特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)
}

其他回答

iOS 10更新

苹果将该方法更改为在主线程上打开async。但是,从现在开始,只能在本机设置中打开应用程序设置。

[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];

iOS 9更新

现在可以直接进入子设置菜单。但是,需要创建URL方案。有两种方法:

XCode -你会在目标,信息,URL方案中找到它。然后,输入prefs。 直接添加到*-Info.plist。增加如下内容: <键> CFBundleURLTypes关键> < / < >数组 < dict > <键> CFBundleTypeRole关键> < / <字符串>编辑字符串> < / <键> CFBundleURLSchemes关键> < / < >数组 <字符串>首选项> < /字符串 > < /数组 < / dict > > < /数组

然后代码:

斯威夫特

UIApplication.sharedApplication () .openURL (NSURL(弦:“首选项:根=一般路径=键盘”)!)

objective - c

[eapplication sharedApplication] openURL:[NSURL优先字符串:

在Swift 3 / iOS 10+中看起来是这样的

if let url = URL(string: "App-Prefs:root=LOCATION_SERVICES") {
    UIApplication.shared.open(url, completionHandler: .none)
}

在iOS 10上测试。工作

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;
}
}

快乐编码:)

你可以在iOS 5.0及更高版本上使用这个:这个不再有效。

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

在Swift 3中,我所需要的是这个(例如重定向到我的应用程序通知):

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。

这只适用于我设置在后台。它会将你重定向到你的应用通知设置但如果设置没有在后台运行它会将你重定向到一般的通知设置。