I’ve built an app that connects via Bluetooth to a device. The device sends up, down, left and right commands.
I want to build an SDK for other third party developers to use so that whenever a third party app with the SDK opens, if we press a button on the device, my app which captures the button press should be able to forward the event to the third party app.
I want to achieve this with the lowest latency possible so that I can enable a variety of use cases like simple games and interactions within other apps.
What would be the best way for me to achieve this as part of my SDK and my app?
Doing what you’re suggesting on iOS isn’t really feasible. There are two potential sticking points:
- Running in the background
- Inter-process communication (IPC)
I talk about the first in general terms in iOS Background Execution Limits. However, in your case this might not be a showstopper because you’re interacting with a Bluetooth LE accessory, and Core Bluetooth does have background execution facilities [1].
The second point is much more problematic. In general, iOS doesn’t allow unmediated IPC between apps from different teams. This isn’t a limitation, but a deliberate design decision based on security and privacy policy.
The only path forward I see here is for you to ship an SDK that interacts with the Bluetooth accessory directly, that is, from within the process of the app that adopts the SDK. However, that presents other challenges:
- Each app will need to request the Bluetooth privilege from the user.
- You have to find a way to mediate access from multiple apps. You can’t do that on the iOS side because of the aforementioned IPC restrictions. You might be able to get the accessory to help you out here [2].
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Now, whether those background execution facilities are sufficient for your latency needs is another question. I’m not really a Core Bluetooth expert, so I’m not gonna chime in on that. If you search the forums for threads with the Core Bluetooth tag, you’ll find lots of insights into this from one of my colleagues, who is a Core Bluetooth expert. And if this becomes a sticking point, you can start a new thread about that topic specifically.
[2] This depends on what facilities the accessory currently supports, or whether you control the accessory’s firmware and thus could add a facility just for this.