iosmobilebluetoothcore-locationproximity

How can you tell if two phones have come close to each other?


I'm trying to implement a mobile phone app that raises a flag if two users come close to each other in the physical world.

I'm looking for a solution that does not require the apps to be actively open on the users phone to be able to make this determination and raise the flag.

Is this possible? Perhaps by bluetooth, or perhaps by using GPS & time data uploaded from each phone and have server determine if the users were sufficiently close together?

I'm looking for accuracy within <20ft.


Solution

  • I don't think you can do this without OS support. Apple's Core Location framework lets you set up an iPhone to listen for iBeacons and wake up the phone and launch your app in the background if it detects one, but you can't make an iPhone broadcast an iBeacon signal when the phone is locked and your app is suspended. Apple can, but you can't.

    I believe the underlying BLE framework that iBeacons are based on have the same restrictions.

    Apple has worked with public health officials to do what you describe to track COVID19 exposure. You install the app on your phone and it uses BLE to both broadcast an ID and listen for other users running the app, and records other app users that it sees. If somebody comes down with COVID, there is a way to send notifications to everybody who was in close proximity to the infected person.

    EDIT:

    It likely would be possible to do this using recorded GPS data and a server, but it would be a battery, network, and computing hog. (I guess it would not meet your requirements since the app would have to be active in the background and the GPS would have to be powered up at all times.) The GPS takes a lot of power, and unless you were running the GPS constantly you'd miss encounters at your desired < 20ft proximity. If you did collect constant GPS data you'd have to upload it all and then do a BUNCH of batch processing to find proximity hits. You'd want to do a first pass where you use a crude computation with a fairly large distance threshold to throw away data where no other devices were anywhere near, and then a second pass on a dramatically smaller data-set. EVEN with that approach it would mean a LOT of number-crunching.