Support for P2P Connectivity and Network Requests in the Background

We are currently developing an application that runs in the background and continuously scans for other nearby devices via peer-to-peer networking. Generally, the high-level goals are:

  • Scan for nearby devices while the app is in the background state. We only need to discover devices that are also running our app.
  • Read a small token of data from each peer device found (no need for full-duplex connection)
  • Submit this token to our server via a background network request

On Android we have demonstrated this functionality using both Bluetooth LE and WifiDirect service discovery, and background operation is easily achieved with Android services. We are currently trying to expand our application to support cross-platform compatibility between IOS and Android, including IOS<-->IOS and IOS<-->Android discovery (in the background). Is there a way to achieve this desired functionality on IOS?

Answered by Engineer in 797131022

On the other hand Bluetooth LE does indeed provide a solution for this. You would be able to scan for nearby advertising BLE accessories (including an app running on an iOS device) continuously whether your app is in the background or not running (except in cases like user killing the app or turning off Bluetooth).

You can read more about the details and implementation pointers at Core Bluetooth Background Processing for iOS Apps


Argun Tekant /  DTS Engineer / Core Technologies

Before you go further, read iOS Background Execution Limits.

Scan for nearby devices while the app is in the background state. We only need to discover devices that are also running our app.

There is no way to achieve this goal with networking APIs:

  • Most APIs only work while your app is running [1], so this request is equivalent to “How do I run continuously in the background?”

  • Also, an iPhone will typically shut down its Wi-Fi interface on device sleep, relying on WWAN to maintain connectivity.

There may be options available to you with Bluetooth LE, but that’s not my technology so I’ll let others talk about that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] There are exceptions, like URLSession background sessions, but nothing relevant to your requirements.

Accepted Answer

On the other hand Bluetooth LE does indeed provide a solution for this. You would be able to scan for nearby advertising BLE accessories (including an app running on an iOS device) continuously whether your app is in the background or not running (except in cases like user killing the app or turning off Bluetooth).

You can read more about the details and implementation pointers at Core Bluetooth Background Processing for iOS Apps


Argun Tekant /  DTS Engineer / Core Technologies

I have a follow-up question: I've implemented both background BLE central and peripheral, however I'd like the iPhone to be discoverable by non-IOS devices (Android). In the foreground, this is quite easy as I can filter for service UUIDs and read service data readily, however Apple's official documentation states that in the background:

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.

So is it impossible for my Android device to discover my IOS device's BLE advertisement if the IOS device is backgrounded? If not, how would I achieve this desired functionality?

Support for P2P Connectivity and Network Requests in the Background
 
 
Q