简体   繁体   中英

watchOS: CBCentralManager.state is always .unauthorized

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM