CoreBluetooth を使用して、特定の既知の特性に書き込もうとしています。接続された周辺機器で「値の書き込み」アクションを選択し、特性UUIDと書き込みたい値を入力するだけで問題なく実行できるTexas Instruments BLEユーティリティを使用したため、これは可能であると感じています。
私の理解では、これを行うには、電話をかける必要があります
[peripheral writeValue:data forCharacteristic:...];
CBCharacteristic
正しい UUID を持つように構成されたオブジェクトを使用します。
正しい UUID を使用して を作成しようとしましたCBMutableCharacteristic
が、この周辺機器のプロファイルに既存の特性であることがわかっているため、正しいアクセス許可でさえ作成しようとしましたが、周辺機器でその特性を使用して読み取り/書き込み操作を実行しようとすると、次のようなクラッシュが発生します。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CBMutableCharacteristic peripheral]: unrecognized selector sent to instance 0x1ed57690'
そして、これが特性をセットアップして書き込むために使用するコードです。
NSString *characteristicUUIDstring = @"fff1";
CBUUID *characteristicUUID = [CBUUID UUIDWithString:characteristicUUIDstring];
char dataByte = 0x10;
NSData *data = [NSData dataWithBytes:&dataByte length:1];
CBMutableCharacteristic *testCharacteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite value:data permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];
[peripheral writeValue:data forCharacteristic:testCharacteristic type:CBCharacteristicWriteWithResponse];