I want to scan for Bluetooth peripheral in the background and make an API Call with found peripherals. I am doing this.
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)
}
But in the background, this method is not called. Please help me out