本人在開發(fā)中要用到藍(lán)牙連接外設(shè),但是藍(lán)牙在沒打開的情況下,系統(tǒng)每次都提示,我們只需檢測藍(lán)牙是否打開關(guān)閉,下面是解決辦法希望可以幫助到遇到同樣坑的碼農(nóng)!

467360DB-10DC-446F-91A5-560BF8E70729.png
這樣寫在藍(lán)牙未打開時(shí)會(huì)有系統(tǒng)提示框:
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
關(guān)閉代碼:
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
這樣寫就會(huì)關(guān)閉。
options 參數(shù)講解
*
* @seealso CBCentralManagerOptionShowPowerAlertKey 藍(lán)牙系統(tǒng)為關(guān)閉狀態(tài),是否向用戶顯示警告對話框
* @seealso CBCentralManagerOptionRestoreIdentifierKey
*
還有一個(gè)坑iOS 10以上跳轉(zhuǎn)到藍(lán)牙設(shè)置界面代碼發(fā)生變化,以下為解決代碼:
NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Bluetooth"];
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}