【问题标题】:How to open bluetooth settings screen如何打开蓝牙设置屏幕
【发布时间】:2012-11-22 15:48:43
【问题描述】:

我正在使用此代码打开蓝牙屏幕设置:

NSURL *url = [NSURL URLWithString:@"prefs:root=General&path=Bluetooth"];
[[UIApplication sharedApplication] openURL: url];

但它不起作用,我使用的是 iOS 6.0 SDK

【问题讨论】:

  • “它不工作”是什么意思?您期望看到什么,发生了什么?
  • 它没有打开设置 - 屏幕

标签: iphone ios6


【解决方案1】:

我认为在 iOS 5.1 中已弃用打开设置应用程序。

【讨论】:

    【解决方案2】:

    似乎所有编程方式都是通过 url(仅适用于 5.0)或直接修改设置(非公共 api)。

    但是,在 5.1+ 上也必须以某种方式实现,例如“Runtastic”-应用程序在您启动它时就是这样做的(显示询问您是否要打开蓝牙设置的对话框)。

    【讨论】:

      【解决方案3】:

      Swift 3.0 和 iOS 10 及更高版本

      func openBluetoothSettings(){
              let urlBTSet = URL(string: "App-Prefs:root=Bluetooth")
              let objApp = UIApplication.shared
              objApp.openURL(urlBTSet!)
          }
      

      目标-c

      -(void) openBluetoothSettings{
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Bluetooth"]];
      }
      

      所以,在上面的代码中,他们改变的是字符串需要添加“App-Prefs:root=Bluetooth”(这是打开蓝牙设置的例子)

      别忘了:'Goto taget -> info -> URL Types -> Add "prefs" in URL Schemes'

      【讨论】:

      【解决方案4】:

      这是 iOS 6.0 的问题,但对于 iOS 8/9,这是答案,

      转到您的 XCode 项目,在 Info -> URL Types 部分 -> URL Scheme 中的“prefs”下

      在 IOS9 中:让 url = NSURL(string: "prefs:root=Bluetooth")!

      IOS8:让 url = NSURL(string: "prefs:root=General&path=Bluetooth")!

      【讨论】:

        猜你喜欢
        • 2015-10-23
        • 2016-10-05
        • 2016-07-02
        • 2016-01-13
        • 2012-12-04
        • 2016-07-05
        • 1970-01-01
        • 2017-03-24
        • 1970-01-01
        相关资源
        最近更新 更多