好的,因此,我浏览了上千个教程和其他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/

10-17 01:47