sunyoulao 2015-08-06 01:46 采纳率: 0%
浏览 1812

iOS 8 BLE readRSSI delegate call back not firing

如题。
http://www.openradar.me/18476971
问题大概是这样的:
Summary:
There seems to be an issue in the CoreBluetooth framework that us causing all readRSSI() requests to never trigger the new iOS 8 delegate peripheral(peripheral: CBPeripheral!, didReadRSSI RSSI: NSNumber!, error: NSError!)

This issue only occurs once the application has successfully connected to this device once. Upon disconnection and reconnection the application never receives this callback again.
问题的重现过程:
1. connect to BLE device.
2. attempt to read the RSSI value with the method readRSSI()
3. disconnect from BLE device.
4. reconnect to BLE device.
5. attempt to read the RSSI value with the method readRSSI()
在步骤5之后,再无法正常读取rssi值。

还请大神帮忙!

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-04 04:03
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这个问题是由于CoreBluetooth框架在iOS 8中引入了一个新的特性:CBPeripheralDelegateReadRSSI. 这个特性使得在连接到蓝牙设备后,如果尝试读取RSSI值时,会触发一个新的回调函数来处理这个操作。然而,在iOS 7和更低版本的操作系统中,没有这个特性。

    解决这个问题的方法是在你的应用程序中实现CBPeripheralDelegateReadRSSI接口,并确保它在重新连接到蓝牙设备后被调用。以下是一个示例代码:

    import CoreBluetooth
    
    class MyPeripheralDelegateReadRSSI: CBPeripheralDelegate {
        func peripheral(_ peripheral: CBPeripheral, didReceiveMessage message: CBMessage) {
            // 处理收到的消息
        }
        
        func peripheral(_ peripheral: CBPeripheral, didFailToStartAdvertisingWithError error: Error?) {
            // 处理失败的情况
        }
    }
    
    // 创建一个BLE设备
    let bleDevice = CBPeripheral(deviceName: "My Device")
    
    // 设置delegate
    bleDevice.delegate = MyPeripheralDelegateReadRSSI()
    
    // 连接到蓝牙设备
    bleDevice.connect()
    

    这样,当您尝试从蓝牙设备读取RSSI值时,将会调用peripheral(_:didReceiveMessage:)方法。

    评论

报告相同问题?