我使用回调来开发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/