我正在从AppDelegate的didFinishLaunchingWithOptions回调调用scanForPeripheralsWithServices。代码如下所示:从iOS 7升级到iOS 8后,didDiscoverPeripheral不会被调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSLog(@"didFinishLaunchingWithOptions");
// Override point for customization after application launch.
cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[cm scanForPeripheralsWithServices:nil
options:nil];
}
- (void) centralManager:(CBCentralManager*)central didDiscoverPeripheral:(CBPeripheral*)peripheral advertisementData:(NSDictionary*)advertisementData RSSI:(NSNumber*)RSSI{
NSLog(@"Did discover peripheral %@", peripheral.name);
[cm stopScan];
}
升级到iOS 8一切之前运作良好,升级(完全相同的代码,没有一个单一的线被改变),我没有得到任何错误,但也didDiscoverPeripheral是后然而,没有被调用。
我也寻找这个问题的解决方案!非常感谢它完美的工作!我检查了central.state是否是PoweredOn,然后开始在那里扫描。我删除了第一个scanForPeripherals ... – philm5 2014-09-23 21:34:57