我需要一个函数didReceiveWriteRequests的示例实现,当中央iOS设备写入’writeValue:’时,它会在蓝牙iOS外设上运行.
但我搜索网络,找不到例子. Apple文档仍然没有示例代码.
解决方法
我搞定了.这是我的工作代码:
// 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 !!"); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。