简体   繁体   中英

iOS BLE: scanning for multiple UUIDs in background

I'm investigating the maximal amount of service UUIDs which can be scanned in background by Central manager.

It seems, a background scanning doesn't work for UUIDs count > 8. Which means, if I pass any number of UUIDs (eg 50 / 100 / 200 / 500), only the first 8 are discovered. (tested a lot)
In the Console.app, bluetoothd complains that UUID count is more than 9. It's an [info] log. As I understand, it's just a private undocumented logic: 在此处输入图像描述

The central code:

func registerForScanning() {
    // generate IDs
    let services = pregeneratedUUIDs.map { CBUUID(string: $0) }
    // start scanning
    centralManager.scanForPeripherals(withServices: services, options: nil) 
}

The peripheral code:

func generateNextService() {
    let cbUUID = CBUUID(string: pregeneratedUUIDs[pregeneratedUUIDsIndex])
    let service = CBMutableService(type: cbUUID, primary: true)
    peripheralManager.removeAllServices()
    peripheralManager.add(service)
    pregeneratedUUIDsIndex = (pregeneratedUUIDsIndex + 1) % pregeneratedUUIDs.count
}

The questions :

  1. Is a maximum allowed amount documented somewhere (I haven't found)
  2. Why 9: are there any hardware limitations to scan eg for 100 UUIDs?
  3. Have anyone met the same behaviour?
  4. Is there another way to scan for 50/100/200 UUIDs in background?

Having a large list of UUIDs require a lot of RAM in the Bluetooth controller. If every advertisement must be checked against this list, that might also require too much realtime CPU time. I would assume the firmware developers mainly put this restriction to make it easy for themselves because it's a very unlikely use case to match against this many UUIDs. There are also similar (small) limits of the number of concurrently connected devices, the white list size, the resolvable address list etc. All of these limits are not documented or queryable through Apple's API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM