CBCentralManagerStateUnknown

CBCentralManagerStateUnknown

本文介绍了是什么原因导致iOS中的CBCentralManagerStateUnknown?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我在使用这个简单代码时在iPad 2上获得 CBCentralManagerStateUnknown

Why do I get CBCentralManagerStateUnknown on an iPad 2 when using this simple code?

- (BOOL)viewDidLoad {

    bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

    if ([manager state] == CBCentralManagerStatePoweredOff) NSLog(@"CBCentralManagerStatePoweredOff");
    if ([manager state] == CBCentralManagerStatePoweredOn) NSLog(@"CBCentralManagerStatePoweredOn");
    if ([manager state] == CBCentralManagerStateResetting) NSLog(@"CBCentralManagerStateResetting");
    if ([manager state] == CBCentralManagerStateUnauthorized) NSLog(@"CBCentralManagerStateUnauthorized");
    if ([manager state] == CBCentralManagerStateUnknown) NSLog(@"CBCentralManagerStateUnknown");
    if ([manager state] == CBCentralManagerStateUnsupported) NSLog(@"CBCentralManagerStateUnsupported");

}

我无法弄清楚 CBCentralManagerStateUnknown 表示。我该怎么办? 只是说:

I cannot figure out what CBCentralManagerStateUnknown means. What do I do? The Apple docs just say:

我通过蓝牙设备连接以及蓝牙关闭时得到此响应。
如果我尝试运行类似 [manager retrieveConnectedPeripherals] 的东西,我也会在控制台中收到此消息:

I get this response with a Bluetooth device connected, and also when Bluetooth is off.If I try to run something like [manager retrieveConnectedPeripherals], I also get this message in the console:

CoreBluetooth[WARNING] <CBConcreteCentralManager: ...> is not powered on


推荐答案

我知道为什么委托永远不会被调用。因为该对象已从内存中删除。只做一个强大的属性

I know why delegate is never called. Because the object is deleted from memory. Just make a strong property

@property(强,非原子)DiscoverBluetoothDevices * btDevices;

并且在init

@implementation DiscoverBluetoothDevices
- (id) init
{
    self = [super init];
    if(self) {
        centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
        [centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @YES}];

    }
    return self;
}

现在委托被正确调用。

这篇关于是什么原因导致iOS中的CBCentralManagerStateUnknown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 13:57