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

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

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

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


当前回答

斯威夫特4.0

'openURL'在iOS 10.0中已弃用:请使用 openURL:选项:completionHandler:不是

UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)

其他回答

您可以使用下面的代码。

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

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

由于openURL(_::)在iOS 10.0之后已被弃用,请使用open(_:options:completionHandler:)代替。

if let settingsUrl = URL(string: UIApplication.openSettingsURLString)  {
        UIApplication.shared.open(settingsUrl, options: [:]) { completed in
             if !completed {
                 print("Failed opening")
             }
        }
}

UIApplicationOpenSettingsURLString这只会在你之前允许任何权限的情况下起作用。例如位置,照片,联系人,推送通知访问。因此,如果您没有用户的此类权限:

如果是iOS 10或以上版本,

它会打开设置,但随后会崩溃。原因是,你的应用设置里什么都没有。

下面的代码将在iOS设置中打开你的应用程序设置。

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}

由于设备不可用,我无法在iOS < 10上检查这一点。

此外,我可以从一些要点中找到下面的代码,它在iOS 10上也能正常工作。但我不确定这是否会得到苹果审查团队的批准。

https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f

斯威夫特4.0

'openURL'在iOS 10.0中已弃用:请使用 openURL:选项:completionHandler:不是

UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)