Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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
Swift iOS CenterManager在状态更改时不回调_Swift_Bluetooth Lowenergy - Fatal编程技术网

Swift iOS CenterManager在状态更改时不回调

Swift iOS CenterManager在状态更改时不回调,swift,bluetooth-lowenergy,Swift,Bluetooth Lowenergy,我正在用Swift编写我的第一个BLE应用程序,遇到了一个障碍。仅当应用程序启动且管理器在viewDidLoad()中初始化时,才会调用My central manager状态更改事件处理程序。我可以在不回电话的情况下关闭和打开BLE。下面的代码片段;任何帮助都将受到欢迎 class ViewController: UIViewController, CBCentralManagerDelegate, UITextFieldDelegate, UITableViewDataSource, UIT

我正在用Swift编写我的第一个BLE应用程序,遇到了一个障碍。仅当应用程序启动且管理器在viewDidLoad()中初始化时,才会调用My central manager状态更改事件处理程序。我可以在不回电话的情况下关闭和打开BLE。下面的代码片段;任何帮助都将受到欢迎

class ViewController: UIViewController, CBCentralManagerDelegate, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate, CBPeripheralDelegate
{
    //MARK: Properties

    var btManager: CBCentralManager!


    override func viewDidLoad()
    {
        super.viewDidLoad()

        // Initialize CoreBluetooth Central Manager
        btManager = CBCentralManager(delegate: self, queue: nil)
    }


    // Called when BLE changes state
    func centralManagerDidUpdateState(_ central: CBCentralManager)
    {
        switch central.state
        {
            case .poweredOn:
                NSLog("BLE powered on")

            case .poweredOff:
                NSLog("BLE powered off")

            case .unsupported:
                NSLog("BLE unsupported")

            case .unauthorized:
                NSLog("BLE unauthorized")

            case .resetting:
                NSLog("BLE reseting")

            case .unknown:
                NSLog("BLE unknown")
        }
    }
}

你的代码在我看来非常好,我已经使用核心蓝牙很多次了。您在哪个版本的iOS和Xcode上运行此功能?iOS 11和iOS 11.2之间的核心蓝牙存在一些主要漏洞。这很奇怪。Xcode 9.3.1和iOS 10.13.4此外,我还收到了设备发现、连接和断开连接的回拨。