2

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.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • Hi Abhinav is there any specifications need to implement in the Peripheral for receiving data from iOS app? – Tendulkar Aug 20 '13 at 10:59
  • Yes. Apple has defined all the specs at developers portal. Please check and let me know if you are looking for something specific. – Abhinav Aug 20 '13 at 16:21

1 Answers1

2

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

Community
  • 1
  • 1
allprog
  • 16,540
  • 9
  • 56
  • 97