iOS 蓝牙 : Unknown error when writing to characteristic

标签 ios objective-c core-bluetooth bluetooth-lowenergy

在我的应用程序中,我发现我的外围设备具有给定的服务。然后,在继续之前,我会检查是否存在所有需要的特征。

当我为我的特征写入一个值时,回调 didWriteValueForCharacteristic: trigger:

- (void) peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{

    NSLog(@"Did write characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
    NSLog(@"With error: %@", [error localizedDescription]);
}  

并产生这个输出:

Did write characteristic value : <005c> with ID Unknown (<00005004 1212efde 1523785f eabcd123>)
With error: Unknown error.

该值是正确的,特征的 128 位 UUID 也是如此,但在我的外围设备中我从未真正获得写入的值。

有什么可能出错的建议吗?

最佳答案

我最初发送了一个 WriteWithoutResponse,将其更改为 WriteWithResponse 给了我一个 CoreBluetooth[WARNING] error 13 正如@Larme 在注释。这个值corresponded to无效的属性值长度,意味着我发送了错误的数字格式,即我发送了一个 16 位的值,而外围设备期望的是 8 位。

将外设更改为接受 16 位数据解决了这个问题。

关于iOS 蓝牙 : Unknown error when writing to characteristic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14833009/

相关文章:

iOS 核心蓝牙 : centralManager:didConnectPeripheral/didFailToConnectPeripheral: not getting called

ios - 当服务不是 nil 在 iPhone 中运行时,BLE 特征为 nil

ios - 如何将 Objective-C 静态扩展库链接/嵌入到 Xcode 13 项目中?

ios - 在 iOS 应用程序中保持计数器在后台运行

ios - 无法识别的选择器发送到实例 - 仅限 Swift 4

iphone - 如何使用 objectAtIndex 删除 childviewcontroller

ios - 添加到购物车功能 - 核心数据

iOS map View - 缩放以固定然后激活标注

ios - 将 UIAlertAction 标题向左对齐

ios - 检测附近的用户并通过推送通知 iOS 进行通知