Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CBCentralManager状态未被识别_Ios_Bluetooth_Bluetooth Lowenergy_Core Bluetooth - Fatal编程技术网

Ios CBCentralManager状态未被识别

Ios CBCentralManager状态未被识别,ios,bluetooth,bluetooth-lowenergy,core-bluetooth,Ios,Bluetooth,Bluetooth Lowenergy,Core Bluetooth,我实现了centralManagerDidUpdateState函数,该函数在某种程度上不会触发cbcentralmanagerstate未经授权的状态。如果在“设置”中关闭应用程序的蓝牙共享选项,则在重新启动应用程序后,仍会显示CBCentralManagerStatePoweredOn状态。如果我关闭或打开BT共享设置,当应用程序在后台运行时,它甚至会导致应用程序崩溃,并出现我无法调试的错误。(->SIGKILL)。所有代理都已正确设置 有人知道它为什么会崩溃,为什么该函数无法正确检测设置吗

我实现了
centralManagerDidUpdateState
函数,该函数在某种程度上不会触发
cbcentralmanagerstate未经授权的
状态。如果在“设置”中关闭应用程序的蓝牙共享选项,则在重新启动应用程序后,仍会显示
CBCentralManagerStatePoweredOn
状态。如果我关闭或打开BT共享设置,当应用程序在后台运行时,它甚至会导致应用程序崩溃,并出现我无法调试的错误。(->SIGKILL)。所有代理都已正确设置

有人知道它为什么会崩溃,为什么该函数无法正确检测设置吗

代码如下:

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    switch (central.state) {
        case CBCentralManagerStatePoweredOff: {
            NSLog(@"CoreBluetooth BLE hardware is powered off");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"OFF"];
            [[NSUserDefaults standardUserDefaults] setObject:@"OFF" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStatePoweredOn: {
            NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"ON"];
            [[NSUserDefaults standardUserDefaults] setObject:@"ON" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateResetting: {
            NSLog(@"CoreBluetooth BLE hardware is resetting");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"RESETTING"];
            [[NSUserDefaults standardUserDefaults] setObject:@"RESETTING" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnauthorized: {
            NSLog(@"CoreBluetooth BLE state is unauthorized");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNAUTHORIZED"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNAUTHORIZED" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnknown: {
            NSLog(@"CoreBluetooth BLE state is unknown");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNKNOWN"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNKNOWN" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnsupported: {
            NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNSUPPORTED"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNSUPPORTED" forKey:@"beaconPowerStatus"];
            break;
        }
        default:
            break;
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
}

安装一个未捕获的异常处理程序,如本文所述:否则,使用xcode中的断点来找出问题所在。您共享的信息不足以诊断您的问题。谢谢,我实现了代码,但没有异常需要处理。应用程序在调试器窗口中以蓝色显示(lldb)终止,这行代码以绿色突出显示:return UIApplicationMain(argc、argv、nil、NSStringFromClass([PEKAppDelegate类]);带有注释:thread1:SIGKILL信号。这发生在我安装应用程序后,将其置于后台,转到设置并打开或关闭应用程序的蓝牙共享。此外,即使我关闭蓝牙共享,也不会显示“未经授权”状态。您是否已将背景模式设置为bluetooth central?如果没有,那么这可能是一个意外的结果,应该向苹果公司报告。蓝牙共享仅适用于外围设备管理器。我不记得见过中央经理的未授权。啊哈!你当然是完全正确的。我查看了iBeacon示例(我不想再使用其他示例),示例应用程序未在蓝牙共享列表中列出(例如Pebble应用程序)。我删除了我应用程序Xcode中的所有目标功能,但它仍然列在蓝牙共享列表中。也许你能回答我,这是什么原因造成的?谢谢你给我指引了正确的方向。不幸的是,如果你的应用程序进入了那里,它就出不来了。尝试更改应用程序标识符。如果你觉得我帮了你的忙,那么我希望你能对我的一个答案投赞成票。不幸的是,在我们合作解决您的真正问题之前,这个问题是不可能回答的。