Core Bluetooth slow down when sending packets

前端 未结 2 2261
死守一世寂寞
死守一世寂寞 2021-02-19 21:58

I\'m experiencing an issue where the time between writing a value to a characteristic using the

[peripheral writeValue:dataPacket forCharacteristic:writeChar ty         


        
2条回答
  •  渐次进展
    2021-02-19 22:34

    First of all check what you get in:

    -(void) peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic
     error:(NSError *)error {
    
    }
    

    if the error code is 0 that means you are sending value to peripheral WITHOUT confirming it. Check if your periheral implements this method:

    //assuming 
    @property (strong, nonatomic) CBPeripheralManager       *peripheralManager;
    
    - (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests
    {
        NSLog(@"WRITE REQUEST!!! %lu",(unsigned long)requests.count);
        //check if there are data
    
       for (CBATTRequest * req in requests) {
       //send reposnse to Central that you recivied write value and eg / accept / reject the write request
        [self.peripheralManager respondToRequest:req
                                              withResult:CBATTErrorSuccess];
       }
    
    
    }
    

提交回复
热议问题