ios - BLE characteristic is nil when the service is not nil running in iPhone -


in project ,i use ble peripheral connected iphone. when beyond maximum connected distance , communication disconnected, , come back,the communication become connected. after re-connected, characteristic can not write data ! seem characteristic nil service not nil. must run app again characteristic can write data normally. dose have same situation,or idea ? wait help.

    -(void) writecharacteristicvalue:(int )value forcharacteristic:(cbcharacteristic *)charateristic  type:(cbcharacteristicwritetype ) type {     nslog(@"writecharacteristicvalue");      nsdata  *data   = nil;     u8 val = value;      if (nil == serviceperipheral)     {         nslog(@"not connected peripheral");         return ;     }      if (nil == charateristic)     {         nslog(@"no valid characteristic");         return;     }      data = [nsdata datawithbytes:&val length:sizeof (val)];     [serviceperipheral writevalue:data forcharacteristic: charateristic type:type];     nslog(@"datawithbytes value %d",val); } corebluetooth[warning] <cbconcretecharacteristic: 0x1ed5f1c0> not valid characteristic peripheral <cbconcreteperipheral: 0x20002520 uuid = <cfuuid 0x20078a60> be196610-c2a1-5d22-3e71-6851718f9672, name = "finder", isconnected = yes> 

it nslog "no valid characteristic" , think characteristic nil .

the problem solved ! put connected services in nsmutablearray, when peripheral disconnected, failed remove service connected-service array. next time service array, return wrong service had been release. now,i change code , remove disconnected service in time. works well!


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -