IOS Bluetooth BLE writevalue return “Unknown error

2019-08-09 20:26发布

I am developping my first Smart Bluetooth (BLE) software on IOS 6.

I am able to receive notifications and read chracteristics values exchanged with a Nordic Development kit including from a custom GATT profile I have created (with specific UUIDs for service and characteristics).

But, everytime I am trying to write a value in a characteristic, I get the error message Unknown Error without more information. No error code, no CoreBluetooth[WARNING] from XCode.

I have set my service and characteristics attributes permissions to write without authentication. Using a development Nordic tool, I am able to write a value in my characteristic, so it would not be a permission problem.

Here is the code I am using to write the value

uint16_t val = 2;
NSData * valData = [NSData dataWithBytes:(void*)&val length:sizeof(val)];
[testPeripheral writeValue:valData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];

And the callback where the error "Unknown error" is rised

 - (void) peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:
                     (CBCharacteristic *)characteristic error:(NSError *)error
{   
    NSLog(@"Did write characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
    NSLog(@"With error: %@", [error localizedDescription]);

    //code...
}

The error text in the console is

Did write characteristic value : <068c0e00 fedc070c 050b3200 04> with ID Unknown (<4444>)
With error: Unknown error.

The value in the error message is not what I am trying to write??!! 444 is the correct UUID I am using for my tests.

Is the length of the value to write important?

After looking hoirs on the internet and tried a lot tests, I need SO to figure it out. Any advice?

3条回答
唯我独甜
2楼-- · 2019-08-09 20:41

sdespont is right.

I have faced the same problem. Just double click home button and slide up to terminate the app, then relaunch it, then the BLE works! I think it's located in the device DB management, we should cancel connections even during debug.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-09 20:43

You should check the CBCharacteristic's properties. if the properties indicate the Characteristic unwritable, You may will get this error.

Good luck.

查看更多
Viruses.
4楼-- · 2019-08-09 20:50

The problem was located in the device DB management, not in the IOS side. But, without error code from CoreBluetooth, it was hard to figure it out!

查看更多
登录 后发表回答