簡單的說 就是只要使用到 CBCentralManager, 就要增加這個Key
在 info.plist 增加 NSBluetoothAlwaysUsageDescription 機碼
Privacy – Bluetooth Always Usage Description
NSBluetoothAlwaysUsageDescription
如果要能在 iOS 12.x 繼續使用, 則保留以前使用的 NSBluetoothPeripheralUsageDescription
實務上, info.plist 共使用下面幾個
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Play with BLE Compatible devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Play with BLE Compatible devices</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
func centralManagerDidUpdateState(_ central: CBCentralManager) { switch( central.state) { case .poweredOff: // "Bluetooth powered off" case .poweredOn: // "Bluetooth powered on"
// Do Scanner Peripherals case .resetting:
// case .unauthorized: // "Bluetooth unauthorized" case .unknown: // case .unsupported: // default: // } }
另外別太相信有些教學的 RePaired功能
已經把 Peripherals 斷電, 但 retrievePeripherals() 還是回傳找到 Peripherals....
我的作法是重新呼叫 CBCentralManager.init() 一且重頭來
這也是為何連線一些藍芽耳機要把藍芽關閉重開的原因
The Ultimate Guide to Apple’s Core Bluetooth
Property List Key: NSBluetoothAlwaysUsageDescription
A message that tells the user why the app needs access to Bluetooth.
Property List Key: NSBluetoothAlwaysUsageDescription
A message that tells the user why the app needs access to Bluetooth.
Changed Bluetooth initialization on iOS13
沒有留言:
張貼留言