gpt4 book ai didi

iOS CoreBluetooth 不太可能的错误

转载 作者:行者123 更新时间:2023-11-29 10:29:49 28 4
gpt4 key购买 nike

我正在开发一个使用 Core Bluetooth 的 Appcelerator 模块。我可以毫无问题地连接到外围设备,并订阅一个特性。我已经实现了所有委托(delegate)函数并且一切似乎都按预期触发,除了我在尝试读取或写入时遇到“不太可能的错误”。我的主要方法如下所示。

-(void)readValueForCharacteristicByUUID:(NSString *)uuidstring
{
if (self.connectedService)
{
CBMutableCharacteristic* characteristic = [self characteristicFromUUIDstring:uuidstring];
if (characteristic)
{
[self.connectedPeripheral readValueForCharacteristic:characteristic];
}
} else {
NSLog(@"[INFO] No service to read");
}
}

-(void)writeValue:(NSData*)value ForCharacteristicByUUID:(NSString*)uuidstring
{
if (self.connectedService)
{
CBMutableCharacteristic* characteristic = [self characteristicFromUUIDstring:uuidstring];
if (characteristic)
{
[self.connectedPeripheral writeValue:value forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
} else {
NSLog(@"[INFO] No service to write to");
}
}

-(CBMutableCharacteristic*)characteristicFromUUIDstring:(NSString*)uuidstring
{
for (CBMutableCharacteristic* c in self.connectedService.characteristics)
{
if ([c.UUID.UUIDString isEqualToString:uuidstring])
{
return c;
}
}
NSLog(@"No Characteristic found with that uuid");
}

我认为这可能是权限问题,所以这是我用来在外围设备中创建特征的代码。

CBMutableCharacteristic* c = [[CBMutableCharacteristic alloc] initWithType:cuuid
properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite|
CBCharacteristicPropertyNotify
value:nil
permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];

最佳答案

来自CBMutableCharacteristic class reference

CBMutableCharacteristic objects represent the characteristics of a local peripheral’s service (local peripheral devices are represented by CBPeripheralManager objects).

您不能将 CBMutableCharacteristic 实例与 CBCentralManager 一起使用来与远程外围设备通信。

在调用 discoverCharacteristics:forService: 之后,您必须使用返回到外围设备的 peripheral:didDiscoverCharacteristicsForService:error: 委托(delegate)方法的 CBCharacteristic在连接的 CBPeripheral 上。

关于iOS CoreBluetooth 不太可能的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30267227/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com