CoreBluetooth CBCentralManager委托方法未被触发

时间:2014-02-05 05:03:32

标签: ios ipad ios7 core-bluetooth cbcentralmanager

我已经使用CoreBluetooth框架扫描所有服务,并在我第一次启动我的应用程序时获得它运行良好的外围设备,但是如果我弹出到上一课并再次从该课程中来,我的CBCentralManger的委托方法没有得到触发了

但是第二次调用下面的方法

 -(void)centralManagerDidUpdateState:(CBCentralManager *)central {
if (central.state != CBCentralManagerStatePoweredOn) {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"BLE not supported !" message:[NSString stringWithFormat:@"CoreBluetooth return state: %ld",central.state] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}
else {
    [central scanForPeripheralsWithServices:nil options:nil];

}

}

但在此之后它没有被触发其余的委托方法

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral   *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
}

-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
}

- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
}

任何人都可以告诉我不调用这些委托方法的可能性是什么?

1 个答案:

答案 0 :(得分:0)

您不需要使用那个凌乱的框架(Core Bluetooth), 有一个很好的解决方案 - LGBluetooth 它适用于CoreBluetooth并提供基于现代块的api。

https://github.com/DavidSahakyan/LGBluetooth

它非常易于使用

    [[LGCentralManager sharedInstance] scanForPeripheralsByInterval:15
                                                         completion:^(NSArray *peripherals)
     {
     }];

这是一个扫描外围设备的例子

相关问题