CoreBluetooth - iPhone advertising in backgrund mode

I am working on an iPhone and Mac OS X application that allows you to lock and unlock your Mac through proximity. It means that if the signal level is below a certain threshold or the connection is lost, it blocks the macro.

I work with the Apples CoreBluetooth base for BTLE, using the iPhone as a peripheral and the Mac as a central one. So far, so good. It is also very good, but when I send the app to the background on the iPhone, the ads seem to change. The iPhone still advertises, but without the service profile and features that I use in the application. Although this is not a problem when the iPhone is still in range of the Mac, since it is still connected and the features are not used in the center, it becomes a problem after the iPhone leaves the range. As expected, the Mac locks and starts detecting to reconnect the iPhone and unlock if it succeeds.

But in this discovery, I use the specified service profile and features to get only the devices that launch my application and identify the one that opens to unlock.

I tried a workaround, opening without a service profile and determining the correct device through my UUID, which I saved when I started using this iPhone to lock and unlock. This workaround also works in a small amount, because when I turn off Bluetooth on the iPhone and turn it on again, it gets a different UUID. This is a limitation with which I could live, but it also changes the UUID after a few hours, and then the unlock does not work.

Perhaps someone has already worked on a similar application and knows how to fix such a problem? Or do you know the static value that I can use to identify the device?

+6
source share
1 answer

So, it seems, as usual, Apple has some strange and unique things happening within their framework. When you advertise an iOS device (for example, your iPhone), there are two “storage areas” for advertising - the usual one that any scan of the device can see, and the “overflow” that can only be seen by iOS that specifically scan it. When your app is advertised in the background, all the UUID services you advertise fall into this overflow area, unfortunately, so it seems like only other iOS devices can see it, not your Mac. From CBPeripheralManager Docs :

Any universal unique service identifier (UUID) contained in the value of the CBAdvertisementDataServiceUUIDsKey key that does not fit into the allocated space is added to the special "overflow" area; they can only be detected by an iOS device that explicitly scans them. While your application is in the background, the local name is not advertised and all service UUIDs are placed in the overflow area.

+5
source

Source: https://habr.com/ru/post/947843/


All Articles