gpt4 book ai didi

ios - 外围设备的中心写入特性(iOS 核心蓝牙)

转载 作者:行者123 更新时间:2023-12-01 17:52:00 24 4
gpt4 key购买 nike

好的,所以我已经浏览了一千个教程和其他 Stack Overflow 线程(所以请不要在没有回答问题的情况下将其列为重复),我无法弄清楚如何使用此功能。

我已按照本教程进行操作:
http://code.tutsplus.com/tutorials/ios-7-sdk-core-bluetooth-practical-lesson--mobile-20741

我有一个系统,中央可以连接到外围设备并从中读取特征。

我现在正试图让我的中心重写特征内的数据,但我发现我调用的写入行被忽略了。

我已经在我的外围类中声明了我的特征:

self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID] properties:CBCharacteristicPropertyNotify|CBCharacteristicPropertyWriteWithoutResponse|CBCharacteristicPropertyRead value:nil permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];

在我的 centralManager 中,我调用了
 [peripheral writeValue:[@"rewritten!" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];

但是这条线被忽略了。谁能告诉我可能出了什么问题?我需要向我的外围类添加一个方法吗?

此外,我已经尝试过使用 WithResponse 进行操作,但它甚至都没有从外围设备调用该方法。

最佳答案

你还在纠结这个问题吗?

我猜您的问题仍然存在,因为您尚未实现 didReceiveWriteRequests方法。

// Processes write command received from a central.

- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests
{

CBATTRequest *request = [requests objectAtIndex:0];
NSData *request_data = request.value;
CBCharacteristic *write_char = request.characteristic;
//CBCentral* write_central = request.central;
//NSUInteger multi_message_offset = request.offset;

// Face commands this PWR RX to advertise serno UUID?
int total_write_requests = 0;
if ([ write_char.UUID isEqual:[CBUUID UUIDWithString:YOUR_CHARACTERISTIC_UUID]] )
{


// Read desired new_state data from central:
unsigned char *new_state = (unsigned char *)[request_data bytes];
my_new_state = new_state[0];
#endif
NSLog(@"- advertise serno UUID: %s", my_new_state ? "TRUE" : "FALSE" );

// Select UUID that includes serno of PWR RX, for advertisements:

++total_write_requests;
}

if ( total_write_requests )
{
[peripheral respondToRequest:request withResult:CBATTErrorSuccess]; // result = success
}
else
{
NSLog(@"_no_write_request_FAULT !!");
}
}

注释掉 [peripheral respondToRequest:request withResult:CBATTErrorSuccess]; ,就像你的情况一样,你正在使用 CBCharacteristicWriteWithoutResponse。

代码取自: where is example of iOS Bluetooth LE peripheralManager didReceiveWriteRequests

关于ios - 外围设备的中心写入特性(iOS 核心蓝牙),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193041/

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