CBCentralManager始终在iOS 11.1.x上返回.poweredOff状态

Sur*_*eet 4 bluetooth core-bluetooth swift ios11.1.1

我正在开发一个BLE项目,因为我启动了CBCentralManager,并扫描可用的设备.我能够扫描并连接可用的BLE外围设备.一切正常,直到我没有在iOS 11.0.x版本上测试过.
当我在iOS 11.1.1或11.1.2上测试时,CBCentralManager总是在启动应用程序时返回我的poweredOff状态.但是,当我打开控制中心,关闭并再次打开蓝牙或激活/停用FlightMode(自动关闭/开启蓝牙).应用程序开始扫描BLE外围设备,一切看起来都很好,直到重新启动app.有没有人在iOS 11.1.x上遇到这样的问题并能够解决这个问题,请帮助解决这个问题.

下面是我检查状态的代码

func initiateCentralManager(){
      manager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey : "MyBLECurrentState"]) 
}

 func centralManagerDidUpdateState(_ central: CBCentralManager){
       print("Received CBCentralManager state")
        peripheralArray.removeAll()
        if central.state == .poweredOn {
            print("poweredOn")
        } else if central.state == .poweredOff {
            print("poweredOff")

        }
    }
Run Code Online (Sandbox Code Playgroud)

ant*_*nem 15

这是正在发生的事情

iOS有3级蓝牙状态:

  1. 允许蓝牙开启和新连接
  2. 蓝牙开启和新连接不允许
  3. 蓝牙关闭

CBCentralManager将返回poweredOff案件的状态23

处于状态1(蓝牙开启和允许新连接)

  • OFF在设置中切换蓝牙
  • ON在控制中心切换

处于状态2(蓝牙开启和不允许新连接)

  • OFF在设置中切换蓝牙
  • ON在控制中心切换
  • OFF在控制中心切换(按钮将变为白色)

1从州进入2

  • 转到BT设置并单击"允许新连接"

  • 如何通过 CentralManager.state 在代码中确定状态是情况 2 还是情况 3?@安东尼? (2认同)