有時候我們需要開啟藍芽來連結裝置,像是Beacon、Apple Watch或小米手環。那麼如果使用者沒有打開權限怎麼辦?請他/她到設定藍芽 (Setting Bluetooth)去打開囉~
目前iOS SDK尚未有API可以直接改藍芽設定,要是未來Apple有開放的話請再跟我說唷!不過我想應該要等到天荒地老,非常重視用戶隱私的Apple,是不會輕易讓開發者悄悄開啟Bluetooth來進行任何動作。
剛好我們偉大的技術長有無私分享:
/** Theme: iOS 10 Setting Bluetooth IDE: Xcode 8 Language: Objective C Date: 106/03/07 Author: HappyMan Blog: https://cg2010studio.wordpress.com/ */ -(void)openBLESetting { NSURL *bluetoothURLOS8 = [NSURL URLWithString:@"prefs:root=General&path=Bluetooth"]; NSURL *bluetoothURLOS9 = [NSURL URLWithString:@"prefs:root=Bluetooth"]; NSURL *bluetoothURLOS10 = [NSURL URLWithString:@"App-Prefs:root=Bluetooth"]; if ([[[UIDevice currentDevice] systemVersion] intValue] >= 10) { [[UIApplication sharedApplication] openURL:bluetoothURLOS10]; } else if ([[[UIDevice currentDevice] systemVersion] intValue] >= 9) { [[UIApplication sharedApplication] openURL:bluetoothURLOS9]; } else { [[UIApplication sharedApplication] openURL:bluetoothURLOS8]; } }
這種沒啥邏輯純粹定義的玩意兒,抄,就對了XD~
隨意留個言吧:)~