2012-11-22 119 views
2

我使用这个代码来打开蓝牙屏幕设置:如何打开蓝牙设置屏幕

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

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

+0

”它不工作“是什么意思?你期望看到什么,发生了什么? – occulus

+0

它不会打开设置 - 屏幕 – someone

回答

2

我相信,打开设置应用已在iOS 5.1中弃用。

2

似乎所有的编程方式都是通过url(只能在5.0上运行)或者直接修改设置(非公开api)。

但是,它也必须以某种方式在5.1+上进行,例如“Runtastic”-App在您启动它时完全执行此操作(显示询问您是否打开蓝牙设置的对话框)。

0

这是问题的iOS 6.0,但适用于iOS 8/9这里就是答案,

转到您的XCode项目,信息下 - > URL类型部分 - > “首选项”,在URL方案

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

IOS8:let url = NSURL(string:“prefs:root = General & path = Bluetooth”)!

2

雨燕3.0 & iOS的10及以上的

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

Objective-C的

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

所以,在上面的代码中他们所改变的是字符串需要添加“应用程序,偏好设置:根=蓝牙“(这是打开蓝牙设置的示例)

不要忘记:'转到taget - >信息 - > URL类型 - >添加” prefs“in URL Schemes'

+1

更多详情请查看:http://stackoverflow.com/a/41895271/2006503 –