检查蓝牙状态-Swift 4 [英] Check Bluetooth status - Swift 4

查看:497
本文介绍了检查蓝牙状态-Swift 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xcode中的蓝牙有问题。对于如何检查蓝牙是否开启,我找不到很好的解决方案。我只想要那个。我在网上搜索了一些解决方案,但对我没有任何帮助。关于如何检查蓝牙的任何想法?我导入了CoreBluetooth类,并编写了以下代码行:

I have a problem with the Bluetooth in Xcode. I can’t find a great solution on how to check if Bluetooth is on or not. I want just that. I searched around the web some solution, but nothing works for me. Any idea on how to check Bluetooth? I imported the CoreBluetooth class and I made this line of code:

if CBPeripheralManager.authorizationStatus() == .denied { code }
if CBPeripheralManager.authorizationStatus() == .authorized  { code }


推荐答案

实现 CBCentralManagerDelegate 委托。

 var manager:CBCentralManager!

 viewDidLoad() {      // Or init()
     manager          = CBCentralManager()
     manager.delegate = self
 }

委托方法:

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    switch central.state {
    case .poweredOn:
        break
    case .poweredOff:
        print("Bluetooth is Off.")
        break
    case .resetting:
        break
    case .unauthorized:
        break
    case .unsupported:
        break
    case .unknown:
        break
    default:
        break
    }
}

这篇关于检查蓝牙状态-Swift 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆