I can’t address the App Review side of this. For that, I recommend that you follow the advice above. However, I can discuss the technical aspects of this.
Can the app open a WebSocket connection in the background … triggered by BLE activity from a registered accessory?
Probably.
In general, iOS supports networking in the background. The key gating factor is runtime. Your app can’t do any networking while suspended [1].
When Core Bluetooth resumes your app in the background, it gives it a very short amount of background execution time, on the order of a few seconds. You may be able to extend that using a UIApplication
background task [2], but still not for long. If your app can get its WebSocket work done in that amount of time, you’re all set.
However, there are two significant caveats:
- If the iOS device has WWAN, it’ll typically shut down the Wi-Fi interface when the user is not actively using the device. That’s a problem if the server you’re connecting to is only available via Wi-Fi. For this to work, your server must be available over Wi-Fi and WWAN.
- There’s no guarantee that the device has a working network. If not, or if the network is very slow, you need to come up with a plan for what to do when your WebSocket connection fails. It might make sense to buffer the event. Or you could choose an alternative strategy, such as using a task in a
URLSession
background session [3]. Or if this is a real-time event — meaning that it’s not useful if it arrives late — then the you should just discard it.
If you choose to buffer the event, make sure to do that on disk. Remember that iOS can terminate your app while it’s suspended, and in that case any in-memory buffer will disappear.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] The obvious exception is URLSession
background sessions, but those are actually run by a system process on your behalf.
[2] I have lots of info about those in UIApplication Background Task Notes.
[3] Keep in mind that background sessions only support HTTP[S] tasks, so for that to work you’d have to add an alternative HTTP interface to your server.