ios - Swift - 点击后回调

标签 ios swift bluetooth bluetooth-lowenergy

我使用回调来开发BLEModule。 下面是一个用于检查电源的简单代码。 它在 ViewDidLoad 中运行良好。 但是,为什么 @IBAction 中的代码没有响应?

<小时/>
class ViewController: UIViewController {

    var ble = BLEManager.sharedInstance

    override func viewDidLoad() {
        super.viewDidLoad()

        ble.confirmPower { (result) in
            print(result) //true or false
        }
    }

    @IBAction func checkBtn(_ sender: Any) {
        print("power")
        ble.confirmPower { (result) in
            print(result) //non-response
        }
    }
}

我正在使用回调来开发BLEModule。 下面是一个用于检查电源的简单代码。 它在 ViewDidLoad 中运行良好。 但是,为什么 @IBAction 中的代码没有响应?

最佳答案

centralManagerDidUpdateState被触发时,您的回调将被调用,我相信centralManagerDidUpdateState将在应用程序启动时被触发,因此您的viewDidLoad中的回调将被调用。但是,当您按下按钮时,不会触发 centralManagerDidUpdateState,因此不会调用回调。

关于ios - Swift - 点击后回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42664439/

相关文章:

bluetooth - 蓝牙中的ACL和SCO Link有什么区别?

android - 如何在android蓝牙文件传输上检测EOF?

ios - 访问 cellforrow 之外的 tableview 内容

ios - OCMock - 验证方法调用的顺序。还有别的办法吗?

ios - 并行多个快速动画不起作用

ios - Swift - 停止 avaudioplayer

ios - 在 swift 中设置 UITextfield 占位符的字体

android - 蓝牙 : onConnectionStateChange Status 8 on Samsung phones

ios - 从 AVPlayer 获取 HLS 的 PCM 数据

ios - paytm 成功后无法导航回我的应用程序