【问题标题】:URL Scheme "Open Settings" iosURL方案“打开设置”ios
【发布时间】:2014-11-17 06:07:17
【问题描述】:

我知道这个问题已经被问过很多次了。答案说这在 Xcode > 5.x 中不可用。但我看到了一些可以使用它的应用程序(转到设置)(iOS7)。有没有办法做到这一点?它在 Xcode 6 中可用吗? Facebook 可以检测蜂窝数据和 wifi

【问题讨论】:

  • 这些都是系统消息,不是应用程序消息。从 iOS 8 开始,您只能启动应用自己的设置页面。
  • 有没有办法让我显示这些系统消息?在 iOS8 中,我可以打开设备的 wifi/蜂窝数据吗?

标签: ios xcode ios7 ios8 url-scheme


【解决方案1】:

从 iOS 8 开始,可以通过以下方式启动直接打开隐私应用部分的设置应用:

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

在斯威夫特中:

if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.sharedApplication().openURL(settingsURL)
}

在 Swift 3.0 中:

if let settingsURL = URL(string: UIApplicationOpenSettingsURLString + Bundle.main.bundleIdentifier!) {
    UIApplication.shared.openURL(settingsURL as URL)
}

【讨论】:

  • 有谁知道如何只打开设置应用而不是个人设置? Facebook 做到了。
  • @Pei 在 url scheme 中指定你应用的 bundle id:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@BundleID", UIApplicationOpenSettingsURLString]]];
  • 这是用于 swift 代码以防万一:guard let bundleIdentifier: String = NSBundle.mainBundle().bundleIdentifier else { return } if let url = NSURL(string: UIApplicationOpenSettingsURLString + bundleIdentifier) { UIApplication .sharedApplication().openURL(url) }
  • @AleksanderAzizi 在 URL 方案中指定应用程序的捆绑 ID 似乎没有什么区别。
【解决方案2】:

1.- 添加 URL 类型

2.- 使用:

目标 - C

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];

斯威夫特

 UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=General")!)

3.- 在这个答案中找到其他路径:iOS Launching Settings -> Restrictions URL Scheme

【讨论】:

  • 是的,在 iOS 10 中坏了,你们找到解决方法了吗
  • 如其他答案所述,将“prefs”替换为“App-Prefs”以使其在 iOS 10 中运行。
  • 注意:如果您使用prefs:root,您的应用可能会被拒绝
  • 我的应用因使用此功能而被拒绝。考虑改用 UIApplicationOpenSettingsURLString 但不会重定向到我想要的位置。
【解决方案3】:

这在 iOS 11 中不再可能了,我们只需打开设置即可。这里是 Swift 4 代码 sn-p:

if let url = URL(string:UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}

【讨论】:

    【解决方案4】:

    屏幕截图上的警报是系统警报。 第一次发生在应用程序想要使用互联网并阻止应用程序的蜂窝数据(并且未连接 Wifi)时。第二种情况发生在应用程序想要使用位置服务,而您已关闭 wifi 时。 无法控制这些警报的显示

    在 iOS 8 (Xcode 6) 中,可以直接从应用程序打开设置。请阅读以下主题: How to open Settings programmatically like in Facebook app?

    Opening the Settings app from another app

    【讨论】:

    • 如何显示第一个?比如,如果我试图从我的 webview 打开 url,这意味着我需要使用互联网,警报会显示吗?可以举个例子吗?
    • 关闭您的应用程序。关闭无线网络。转到设置->蜂窝->在“将蜂窝数据用于:”部分中找到您的应用并禁用它。打开您的应用。
    • 如果您从苹果商店下载了一个应用程序并且该应用程序需要使用互联网,它是否会自动添加到使用蜂窝数据的应用程序列表中?我的应用没有出现在列表中,是否正常,因为它只是一个测试?
    • 我不知道是否有任何标志表明这个应用程序需要互联网访问。我做了一个简单的测试。我使用单视图应用程序创建了项目,并在 AppDelegate didFinishLaunchingWithOptions 添加了 Line: [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"facebook.com"]] returnedResponse:nil error:nil]; 关闭 wifi 并启动应用程序。之后该应用程序出现在名单上。
    【解决方案5】:

    iOS 13、斯威夫特 5.0

    打开设置的语法 [再次] 稍微改变了一点。

    if let url = URL(string:UIApplication.openSettingsURLString) {
         if UIApplication.shared.canOpenURL(url) {
           UIApplication.shared.open(url, options: [:], completionHandler: nil)
         }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 2016-01-25
      • 2012-02-20
      • 1970-01-01
      • 2014-05-02
      • 2016-10-22
      相关资源
      最近更新 更多