我正在從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