我正在Swift中编写我的第一个BLE应用程序并遇到了障碍。我的中央管理器状态更改事件处理程序仅在应用程序启动时调用,并且在viewDidLoad()中初始化了管理器。我可以在没有回电的情况下关闭和打开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")
}
}
}