0
私はCore Bluetooth Macアプリケーションで作業していましたが、私はMac上で発見部分の問題に遭遇しました。このコードは、私のmacのBluetooth設定で同じデバイスが表示されているにもかかわらず、デバイスを検出できませんでした。明らかにそれはコードの問題ですが、私はそれを把握していないようです。コード:私のMacがこのコアBluetoothアプリケーションのデバイスを検出しないのはなぜですか?
import Cocoa
import CoreBluetooth
class ViewController: NSViewController, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
override func viewDidLoad() {
super.viewDidLoad()
centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main)
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
func setupBT() {
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
var statusMessage = ""
switch central.state {
case .poweredOn:
statusMessage = "Bluetooth Status: Turned On"
case .poweredOff:
statusMessage = "Bluetooth Status: Turned Off"
case .resetting:
statusMessage = "Bluetooth Status: Resetting"
case .unauthorized:
statusMessage = "Bluetooth Status: Not Authorized"
case .unsupported:
statusMessage = "Bluetooth Status: Not Supported"
default:
statusMessage = "Bluetooth Status: Unknown"
}
print(statusMessage)
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("Discovered")
}
}
「オンになっていますが、「発見」されていません。私は複数のBluetoothデバイスとスピーカーを試しました。
CoreBluetoothにデバイスの検出を指示していません。あなたは 'scanForPeripherals'を呼び出す必要があります – Paulw11