0

我已经使用 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
{
}

谁能告诉我不调用这些委托方法的可能性是什么?

4

1 回答 1

0

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

https://github.com/DavidSahakyan/LGBluetooth

超级好用

    [[LGCentralManager sharedInstance] scanForPeripheralsByInterval:15
                                                         完成:^(NSArray *外围设备)
     {
     }];

这是扫描外围设备的示例

于 2014-02-07T14:23:48.617 回答