ios7 - core bluetooth crash in iOS 7 -


i have developed bluetooth app, runs fine on ios 6, when run on ios 7 application crashes in -diddiscoverperipheral call back. crash info suggests release called on cbperipheral object. have used arc memory management, here declaration,initialisation of cbperipheral object , call code:

@interface brlediscovery () <cbcentralmanagerdelegate, cbperipheraldelegate> {     cbcentralmanager    *centralmanager;     cbperipheral *currentperipheral;     bool                pendinginit; }   - (id) init {     self = [super init];     if (self) {         pendinginit = yes;         centralmanager = [[cbcentralmanager alloc] initwithdelegate:self queue:dispatch_get_main_queue()];        currentperipheral=[[cbperipheral alloc]init];         founddevice=false;         foundperipherals = [[nsmutablearray alloc] init];         connectedservices = [[nsmutablearray alloc] init];      }     return self; }  - (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi { nslog(@"found peripheral %@",[peripheral name]);      if ([[peripheral name] isequaltostring:peripheralname]) {         founddevice=true;         currentperipheral=peripheral;          if (![foundperipherals containsobject:peripheral]) {             [foundperipherals addobject:peripheral];             [discoverydelegate discoverydidrefresh];             [discoverydelegate discoverydidfinddevice:peripheral];          }          [recursivescantimer invalidate];     }   } 

from description, it's pretty crashing on line:

currentperipheral=peripheral; 

to me, it's kinda messy allocating cbperipheral object in init , assigning peripheral @ unknown time later (especially arc). if want keep reference discovered peripheral, create cbperipheral object in interface, retain discovered peripheral, , assign interface peripheral.

just try this:

currentperipheral = [discoveredperipheral retain];//where discoveredperipheral 1 given in delegate callback 

i don't use arc of corebluetooth related applications..you need careful corebluetooth framework , peripheral references though...it gets messyyy.

note: if not need have direct contact peripheral, it's handy keep record of cfuuidref (or identifier ios 7) , retrieve peripheral whenever need it... luck!


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -