Advertising in background, getting UUID

Hello


I work on iOS application with acts as Bluetooth peripheral. I need to implement a searching for my iOS peripheral from non iOS centrals. I’m faced with a problem while my iOS application advertising in background mode. When it is advertising in foreground, my central can read primary service UUID from advertising data, but when it is advertising in background, I can’t see the name or the UUID of peripheral – there is only Apple manufacturer data in advertising packet.


The essence of the problem lies in the fact that my non iOS central can’t determinate – is it advertising my peripheral in background or any other peripheral in background. I have to connect every iOS device with advertising in background, enumerate its services to look for my service UUID.


The documentation says that during background advertising all service UUIDs go to special “overflow” area and only iOS devices can read it specifying service in CBCentralManager’s scanForPeripherialWithServices method. It looks like Apple have an ability to check background advertising packet data for service UUID.


After searching on StackOverflow I found some interesting information about service hashed UUID. Background mode advertising packet always contains Apple manufacturer data (14 FF 4c 00 01) and undocumented 128 bit value, where one of these 128 bits equals 1. I tried to change my service UUID several times and found out than this 128 bit value after Apple manufacturer data changes too.


  1. I’d like to use this value to filter peripherals around and reduce connections to wrong (not mine) peripherals. Can you give any information how this value depends on service UUID? Is there any hash function that is used on specified service UUID in scanForPeripherialWithServices method?
  2. If the information about this mechanism is confidential, please tell, will the background advertising packet always be the same for the immutable service UUID which will never change?
  3. Is there any other way to send my custom information while advertising in background mode? Maybe I can add my data into BLE SCAN RESPONSE packet?


Best Regards,
Dezmond

Replies

Is your iOS background device doing anything like handoff or continuitiy?


If you use iMessage, Safari, Mail or anything like that, your iOS device will start broadcasting Apple's Continuity Service. This is probably higher priority than the service I assume you are providing in your advertisement dictionary for the peripheralmanager.


I have done background advertisement with a UUID and it gets discovered just fine.


Can you provide a snip of your code demonstrating how you're setting up your peripheral manager advertisement data? Be sure that you check the acts as a bluetooth peripheral background mode too! That can be a gotcha if you copy paste and forget to check it.

No, I don't do anything like handoff or continuitiy and I don't use any Apple specific services like iMessage. I'm developing my own custom service, which must do advertising in background ⚠ mode.


I suppose, you were able to discover it using another ios device. If you use some king of BLE sniffer, you will see than there is no UUID or device name in advertising data when advertising from background. There is explanation in Core Bluetooth Programming Guide

The bluetooth-peripheral Background Execution Mode

To perform certain peripheral role tasks while in the background, you must include the

UIBackgroundModes
key with the
bluetooth-peripheral
value in your app’s
Info.plist
file. When this key-value pair is included in the app’s
Info.plist
file, the system wakes up your app to process read, write, and subscription events.

In addition to allowing your app to be woken up to handle read, write, and subscription requests from connected centrals, the Core Bluetooth framework allows your app to advertise while in the background state. That said, you should be aware that advertising while your app is in the background operates differently than when your app is in the foreground. In particular, when your app is advertising while in the background:

  • The
    CBAdvertisementDataLocalNameKey
    advertisement key is ignored, and the local name of peripheral is not advertised.
  • All service UUIDs contained in the value of the
    CBAdvertisementDataServiceUUIDsKey
    advertisement key are placed in a special “overflow” area; they can be discovered only by an iOS device that is explicitly scanning for them.
  • If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.



There must be the way to check UUID using Apple specific manufacturer data.

I can post my soures tomorrow. but it's absolutelly common. It works file in foreground mode and I see that it advertises in background too (but with different advertising data)

Did you found any solution ?

No, it looks like it impossible without pairing. You can find iOS peripheral which is advertising in background mode from non iOS central only if you have done pairing and bounding with it before

I met the same problem, but I don't quite understand you mean, you can specific explanation? Thank you very much!

So did you find any other solution to this or the only way to find the peripheral device advertising in the background from a non iOS central now is only if we have paired it with before?

I'd like to follow up as well. Has anyone you found any other solution beyond pairing?

One way to improve connection management of non-Apple BLE central to Apple BLE peripherals (such as an iPhone, advertising as a BLE peripheral) in background is to scan for all devices in the immediate vicinity (possibly filtered by advertisement packet RSSI value) and enumerate them based on their unique advertisement address (aka Bluetooth MAC address).


During connection your central can determine each device capabilities, find your target devices and track them by the MAC address.

Since iOS devices change their Bluetooth advertisement address every 15 minutes or so, your central should be ready to remove/add target devices with new address as needed.

Why is that a problem?



My iPhone does some Advertising and i am able to put any UUID in the advertising. After the iPhone goes in background the UUID is moved to the " overflow" area. What i do next?

I write down what is in the overflow area and try the next UUID and next UUID and write it down. You be able to see that the overflow is always the same for your UUID. so your central can filter for it!

Objectivec have the function but not for swift (maybe it could have... but i couldn't find it)😝