简体   繁体   中英

IOS Developpement : Background BLE Precisions on Apple doc

I everyone,

I'm trying to develop two apps that act as a central and a peripheral, which automatically connect to each other when they enter in the bluetooth range while both are in background .

I posted something about my issue (because none of my tests were conclusive) on this post : IOS Developpement : Background BLE scanning .

The answer I always find on the internet directly come out of the Apple documentation. One post example ( https://stackoverflow.com/a/20460113/5464805 ):

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.

But there is something I don't understand: In my central, I already specify the UUID [centralmgr scanForPeripheralsWithServices:[NSArray arrayWithObject:servicesUUID] options:scanOptions]; . According to the functionning detailed above, it shouldn't connect when the peripheral is in background and the central in foreground, but it does !

Does somebody have an idea on what is happening in this specific case ? Or maybe a solution to make my two devices connect while in background ?

Thank you!

PS: Also the answer I found is pretty old (2013).

I think that when the central is in the foreground it can wake the peripheral up to retreive the UUID when the peripheral has been detected, but when the central is in the background it cannot. That is why it will not work to have both sides in background mode.

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