简体   繁体   English

watchOS:CBCentralManager.state 始终未授权

[英]watchOS: CBCentralManager.state is always .unauthorized

I am trying to use CBCentralManager in watchOS to scan for BLE devices.我正在尝试在 watchOS 中使用CBCentralManager来扫描 BLE 设备。 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):这会导致调用以下 function(如预期的那样):

internal func centralManagerDidUpdateState(_ central: CBCentralManager) {

Problem: central.state is always .unauthorized问题: central.state总是.unauthorized

I have included Privacy - Bluetooth Always Usage Description and Privacy - Bluetooth Peripheral Usage Description in info.plist for both the watchApp and watchAppExtention.我在 info.plist 中为 watchApp 和 watchAppExtention 包含了Privacy - Bluetooth Always Usage DescriptionPrivacy - Bluetooth Peripheral Usage Description

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).我找到了答案: info.plist中的隐私权限必须放在 iOS 应用程序(而不是 watchOS 应用程序)中。 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 .然后使用以下代码在 iOS 应用程序中发出虚拟请求,用户会弹出请求蓝牙访问权限,原因是您在info.plist中提供的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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