My central manager can detect new peripherals in the foreground and background - I know this because I trigger a UNNotification when it finds a new peripheral.
However, when the device is locked it does not seem to keep scanning for new peripherals.
In my capabilities I have enabled background mode for Using LE accessories, as well as remote notifications. Am I missing something with BLE that can allow me to detect new peripherals when the device is locked?
Update w/ more info:
Here's how I instantiate my central manager and begin scanning:
central = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey : kRestoreIdKey])
central!.scanForPeripherals(withServices: [kMyService, kMyOtherService], options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])
Here's the background mode enabled:
And furthermore, the plist key for the background mode:
Any idea why my local notification will trigger when it scans in the foreground or background, but NOT when the screen is locked?
As a bluetooth-central background app, you should be able to continue scanning when the device is locked, but only if you are scanning for specific service UUIDs.
You cannot scan for arbitrary devices in the background. (It's possible that you get away with it in some cases, but that doesn't mean it's supported.)
That said, the scanning interval can be substantially increased when the device is locked (since there are no foreground apps scanning and the system in general is trying to conserve power by turning off the antenna). If you have a device that also has a long advertising interval (and especially if it doesn't have one of the recommended advertising intervals), then it can take a very long time for the two to discover each other (think minutes, not seconds).
The list of recommended advertising intervals is in Bluetooth Design Guidelines section 3.5.
Useful thread on the topic.