CBCentralManager*经理EXC_BAD_ACCESS与iOS7.0

use*_*311 6 cbcentralmanager

我刚刚升级到Xcode V5.0(5A1413)构建成功但是对模拟器运行程序会导致属性定义出错:

@property(非原子,强)CBCentralManager*经理; - >线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x8)

Bez*_*ewy 2

我遇到了同样的问题,最后求助于这个:

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

在模拟器上,如果我防止创建 CBCentralManager,我会看到centralManagerDidUpdateState: 使用与我的强属性匹配的 CBCentralManager* 进行调用。可以引用,状态为CBCentralManagerStateUnsupported。这是有道理的,但如果我当时将我的强管理器属性归零(因为我不会在不支持它的模拟器上执行任何 BLE),我会得到 EXC_BAD_ACCESS。因此,在没有更好的答案的情况下,我建议您根本不要解雇经理,就像我上面的代码一样。