2013-01-04 13 views
19

ho implementare iOS CoreBluetooth client server & per l'invio dei datiCome implementare correttamente haReceiveWriteRequests? iOS6 CoreBluetooth

client site 
[self.connectedPeripheral writeValue:mainData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse]; 

e

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic 
{ 
    NSString *s= [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]; 
    NSLog(@"didWriteValue characteristic.value: %@ ", s); 
} 

e Site Server

- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests 
{ 
    NSData *res= [[NSString stringWithFormat:@"Hello"] dataUsingEncoding:NSUTF8StringEncoding]; 
[self.peripheral updateValue:res 
         forCharacteristic:self.writeCharacteristic 
        onSubscribedCentrals:nil]; 
[peripheral respondToRequest:aReq withResult:CBATTErrorSuccess]; 
} 

tuttavia, il cliente non può ricevere i dati. Qualche idea? Grazie per il vostro aiuto.

+1

hai trovato alcuna risposta al vostro problema ? Ho la stessa domanda :( – eter

risposta

-2

Per utilizzare:

- (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCharacteristic *)characteristic onSubscribedCentrals:(NSArray *)centrals; 

è necessario prima di abbonarsi utilizzando

- (void)setNotifyValue:(BOOL)enabled forCharacteristic:(CBCharacteristic *)characteristic; 

dal lato client.

2

Secondo doc di Apple su CoreBluetooth, è necessario utilizzare:

- (void)respondToRequest:(CBATTRequest *)request withResult:(CBATTError)result; 

Per rispondere al central.This è anche una scelta quando si riceve una richiesta di lettura

Problemi correlati