IOS Bluetooth BLE writevalue return “Unknown error”

限于喜欢 提交于 2019-12-11 10:23:37

问题


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?


回答1:


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

Good luck.




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/16623013/ios-bluetooth-ble-writevalue-return-unknown-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!