【发布时间】:2016-12-18 12:13:01
【问题描述】:
我正在尝试检测用户 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")
}
}
请您帮我解决这个问题,我是 swift 和 CoreBluetooth 技术的新手。我也在使用 Reachability 来检测 Wi-Fi 连接,所以如果它也适用于蓝牙,那么我更愿意使用 Reachability。
【问题讨论】: