I am trying to use CBCentralManager
in watchOS to scan for BLE devices.
I use the following code to start the scanning process:
centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
This causes the following function to be called (as expected):
internal func centralManagerDidUpdateState(_ central: CBCentralManager) {
Problem: central.state
is always .unauthorized
I have included Privacy - Bluetooth Always Usage Description
and Privacy - Bluetooth Peripheral Usage Description
in info.plist for both the watchApp and watchAppExtention.
Is there something else that I should be doing (eg, include something in the entitlement file)? My app is not a peripheral; it is supposed to be in the "central" mode in foreground (not background).
Thanks!
I found the answer:
The privacy permissions in the info.plist
must be placed in the iOS app (not the watchOS app). Then make a dummy request in the iOS app using the following code and users gets pop up that asks for Bluetooth access permission with the reason that you've provided in the info.plist
.