Reputation: 38162
In my app, I need to write data into a writable characteristics of a peripheral. I am able to do this by following the process of scanning the peripherals, detecting and connecting to peripheral, discover services, discover characteristics and then finally write into the target characteristics.
After all this is done, I keep a reference of CBPheripheral and CBCharacteristic I am interested in. Now, next time, I am trying to directly write into the saved peripheral and characteristics. But I am getting below bluetooth warning. Can't we directly write into a Peripheral characteristics if we are not yet disconnected from it?
BTBeaconTest[1421:60b] CoreBluetooth[WARNING] is not a valid peripheral
[iPeripheral writeValue:dataToWrite forCharacteristic:iCharacterstic type:CBCharacteristicWriteWithResponse];
PS: I did not disconnect from the peripheral.
Upvotes: 2
Views: 1941
Reputation: 16790
Most probably the bluetooth stack has been reset or for some other reason your peripheral became invalid. You need to monitor the state updates and if ever you receive OFF
or RESETTING
, then invalidate all your handles to peripherals and characteristics. Generally it is better to keep reference to the peripheral only and look up the characteristics when you need them. CoreBluetooth is going to cache them for you, so the lookup will be very fast. This answer shows you how to do that: https://stackoverflow.com/a/18091617/768935
Upvotes: 2