代码之家  ›  专栏  ›  技术社区  ›  Max Chang

iOS Bluetooth ScanFor外设后台运行的服务仅适用于某些版本?

  •  0
  • Max Chang  · 技术社区  · 6 年前

    我有一个可以在后台进行外围扫描的工作系统。重构代码后,此功能已停止工作。

    相关章节:

    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        print("did update central manager")
        if central.state == .poweredOn {
            print("powered on central manager")
            let scanOptions = [CBCentralManagerScanOptionAllowDuplicatesKey: true]
    
            central.scanForPeripherals(withServices: [CBUUID(nsuuid: UUID.init(uuidString: "05D27C93-F0FE-43BB-A8CB-DECFED270F8F")!)], options: scanOptions)
        }
    }
    
    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        print(RSSI)
        DataCollector.logBluetoothData(advertisementData, RSSI)
        let uuid = BluetoothModel.extractUUID(advertisementData)
        bluetoothReading[uuid] = (Date().timeIntervalSince1970, Double(truncating: RSSI))
    }
    

    我觉得这可能与用户授权在后台监听和开始监听之间的时间有关,但我不认为这是基于以前版本的工作方式。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Max Chang    6 年前

    问题解决了。如果您也在为iBeacon设备设置范围,那么您可以继续监视它。