Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CBCentralManager *manager EXC_BAD_ACCESS with iOS7.0

I just upgraded to Xcode V5.0 (5A1413) the build success but running the program against the emulator causes the error at the property definition:

@property (nonatomic, strong) CBCentralManager *manager; --> Thread 1:EXC_BAD_ACCESS (code=2, address=0x8)

like image 529
user2793311 Avatar asked Sep 18 '13 22:09

user2793311


1 Answers

I ran into the same issue and finally resorted to this:

UIDevice *currentDevice = [UIDevice currentDevice];
if ([currentDevice.model rangeOfString:@"Simulator"].location == NSNotFound) {
    self.centralMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}

On the Simulator, if I don't guard against creation of the CBCentralManager, I see centralManagerDidUpdateState: called with a CBCentralManager* that matches my strong property. It can be referenced and the state is CBCentralManagerStateUnsupported. That makes sense, but if I nil my strong manager property at that point (since I'm not going to be doing any BLE on a simulator that doesn't support it) I get the EXC_BAD_ACCESS. So, in the absence of a better answer, I suggest you simply guard against firing up the manager at all, as in my code above.

like image 195
Bezewy Avatar answered Sep 22 '22 07:09

Bezewy