1
CoreBluetooth가 탑재 된 iPad에서 MacBook Pro에 연결하려고합니다. 여기CoreBluetooth가 API 오용으로 인해 사용되지 않는 주변 장치에서 연결 해제 중
는 CBCentralManagerDelegate
내 대표입니다 :
extension MasterViewController: CBCentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .poweredOn {
print("Scanning for peripherals")
central.scanForPeripherals(withServices: nil, options: nil)
Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(self.stopScan), userInfo: nil, repeats: true)
}
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("Did discover peripheral", peripheral)
central.connect(peripheral, options: nil)
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
print("Did connect to ", peripheral)
peripheral.delegate = self
self.remotePeripheral.append(peripheral)
}
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {}
}
하지만 스캔 할 때 로그에서이 오류를 얻을 :
<Error>: [CoreBluetooth] API MISUSE: Cancelling connection for unused peripheral
왜 이런 일이 무엇입니까?
CBPeripheral에 대한 참조는 계속 유지해야합니다. 그것은 "판매 대리인"에 관한 것이 아니라'self.remotePeripheral.append (주변기기)'에 관한 것입니다. – Larme
좀 더 설명해 드리겠습니다. http://stackoverflow.com/questions/26377470/ios-corebluetooth-centralmanagerdidconnectperipheral-didfailtoconnectperiph (Objective-C에 있지만 상황은 동일합니다. CoreBluetooth는 그렇지 않습니다. 매개 변수에 대한 강력한 참조를 유지하여 너무 빨리 릴리스 될 수 있음) – Larme