2012-11-22 118 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 –