本文介绍了哪里是例如iOS的蓝牙LE peripheralManager didReceiveWriteRequests的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的功能didReceiveWriteRequests的示例实现其在运行iOS的蓝牙数据时由中央iOS设备做了写它周围'writeValue:
I need an example implementation of function didReceiveWriteRequests which runs at a Bluetooth iOS peripheral when data is written to it by the central iOS device doing a 'writeValue:' .
不过,我搜索网页,并不能找到例子。苹果文档仍然没有样品code。
But I've searched web and cannot find example. Apple docs still have no sample code.
推荐答案
我得到了它的工作。这是我的工作code:
I got it working. Here is my working code:
// 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 !!");
}
}
这篇关于哪里是例如iOS的蓝牙LE peripheralManager didReceiveWriteRequests的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!