0

ble 특성에 쓰기를 시도했습니다. 그러나 반환 오류는 "쓰기가 허용되지 않습니다."입니다.iOS에서 ble 특성에 쓰기 오류

이것은 특성을 발견하는 것입니다. // 지정된 서비스의 특성을 발견하면 호출됩니다.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error 
{ 
    if ([service.UUID isEqual:[CBUUID UUIDWithString:DEVICE_SERVICE_UUID]]) { 
     for (CBCharacteristic *aChar in service.characteristics) 
     { 
      if ([aChar.UUID isEqual:dev2appcharacteristicsUUID]) { 
       [devicePeripheral setNotifyValue:YES forCharacteristic:aChar]; 
       NSLog(@"Found R-Motion device with characteristics: %@\n", aChar); 
       dev2appCharacteristic = aChar; 
      } 
      if ([aChar.UUID isEqual:app2devcharacteristicsUUID]) { 
       //[devicePeripheral setNotifyValue:NO forCharacteristic:aChar]; 
       NSLog(@"Found R-Motion device with characteristics: %@\n", aChar); 
       app2devCharacteristic = aChar; 
      } 
     } 
    } 
} 

제대로 발견 할 수 있습니다. 그리고 app2devCharacteristic에 쓰려고합니다. _properties unsigned long long 4_isNotifying bool false입니다. 나는 오류가 반환되지 있습니다

- (IBAction)RequestResult:(id)sender { 
    unsigned char bytes[] = {0x00, 0xCC, 0xFF};//{0xFF, 0xCC, 0x00};// 
    NSData *transactData = [NSData dataWithBytes:bytes length:3]; 
    [devicePeripheral writeValue:transactData forCharacteristic:app2devCharacteristic type:CBCharacteristicWriteWithoutResponse]; 

} 

로 withoutresponse을 변경 한 경우

가 나는 오류 "Writing is not permitted"

didWriteValueForCharacteristic에서 수익을

- (IBAction)RequestResult:(id)sender { 
    unsigned char bytes[] = {0x00, 0xCC, 0xFF};//{0xFF, 0xCC, 0x00};// 
    NSData *transactData = [NSData dataWithBytes:bytes length:3]; 
    [devicePeripheral writeValue:transactData forCharacteristic:app2devCharacteristic type:CBCharacteristicWriteWithResponse]; 

} 

으로 바이트 배열을 작성했습니다. 하지만 내 주변 장치는 아무것도받지 못합니다.

+0

당신은'_properties unsigned long long 4'가'app2devCharacteristic'을위한 것이라고 말했습니다. 글쎄,'CBCharacteristicPropertyWriteWithoutResponse = 0x04,''writeValue : type : :'의'type'에서'CBCharacteristicWriteWithResponse'를 할 수 없습니다. 나머지 (기록되지 않음)는 어떻게 알 수 있습니까? 'transactData'는 유효합니까? 귀하의 장치가 실제로 그것을 기대합니까? – Larme

답변

0

주변 장치는 각 특성에 대한 사용 권한을 설정합니다. 읽기 및 쓰기 권한은 별도입니다. 쓰기 허용은 단순히 암호화 수준에 관계없이 쓰기 권한이 없다는 것을 의미합니다.

응답없이 쓰기를 사용하면 사양별로 오류 메시지가 전달되지 않습니다.

편집 : _properties는 Bluetooth 코어 사양 3 권 G 섹션 3.3.1.1에서 특성 등록 정보 테이블을 참조한다고 가정하면 4는 응답없는 쓰기는 허용되어야하지만 응답은 기록하지 말아야한다는 것을 의미합니다.