小编Iva*_*van的帖子

如何检测用户的iPhone关闭或开启的蓝牙?

我试图检测用户的iPhone开启或关闭的蓝牙.如果它是关我想发送通知给用户打开它.到目前为止,我已经这样做了:

import CoreBluetooth

  class ViewController: UIViewController, CLLocationManagerDelegate,AVCaptureMetadataOutputObjectsDelegate,CBManager {   

 var myBTManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)

  }

func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager!) {
    print(#function)
    if peripheral.state == CBManagerState.poweredOn {
        print("Broadcasting...")

    //    myBTManager!.startAdvertising(_broadcastBeaconDict)
    } else if peripheral.state == CBManagerState.poweredOff {
        print("Stopped")
        myBTManager!.stopAdvertising()
    } else if peripheral.state == CBManagerState.unsupported {
        print("Unsupported")
    } else if peripheral.state == CBManagerState.unauthorized {
        print("This option is not allowed by your application")
    }
}
Run Code Online (Sandbox Code Playgroud)

但正如你从图中看到的那样,出了点问题.在此输入图像描述

你能帮我解决一下这个问题,我是swift和CoreBluetooth技术的新手.我也使用Reachability来检测Wi-Fi连接,所以如果它也适用于蓝牙,我宁愿使用Reachability.

bluetooth swift

6
推荐指数
1
解决办法
3117
查看次数

标签 统计

bluetooth ×1

swift ×1