Core Bluetooth advertise and scan in the background

I’m afraid what you are trying to do will not work.
I have tried to achieve the same thing.

The problem is the difference in scanning in foreground and background.
When you are scanning for devices in the foreground you can scan for anything. In the background you must specify the actual service UUID you are scanning for. Ok, this isn’t actually a problem as you know the UUID you are looking for.

Peripheral:
Broadcasting as a peripheral again works differently in foreground and background.
In foreground it works like any normal BT peripheral. In the background it has a very limited amount of space to work with, so your peripherals UUID is hidden away and not broadcast. Only when a central device (an iPhone in foreground) requests the information from it will it wake your app and show it’s UUID.

So the 2 cancel each other out. As your background scan can only scan for devices with a specific UUID and your background peripheral cannot advertise its UUID, they cannot see each other.

1 of your devices (either peripheral or central) must be in the foreground to work.

This has been discussed several times on the Apple Bluetooth mail list.

Leave a Comment