【发布时间】:2020-07-24 13:43:00
【问题描述】:
我想在后台扫描蓝牙外围设备并使用找到的外围设备进行 API 调用。我正在这样做。
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
let theViewController = loginVC()
APIManager.sharedInstance.pushtracerData(vc: theViewController, user_id: USERID.sharedInstance.getUserID(), SSID: peripheral.name ?? "", MAC: peripheral.identifier.uuidString, RSSI: "\(RSSI)", TST: "", tracer_or_mobile: "2") {
}
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .poweredOn {
let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey:NSNumber(value: false)]
centralManager?.scanForPeripherals(withServices: nil, options: options)
}
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
self.centralManager = CBCentralManager.init(delegate: self, queue: DispatchQueue.main)
completionHandler(.newData)
}
但是在后台,并没有调用这个方法。请帮帮我
【问题讨论】: