Is it possible to start MQTT Broker in my iOS app?

I want to run an MQTT broker/server in my iOS app as a background thread and my neighbouring devices talk to my app over MQTT topics. I found a similar app in Google playstore. I am not sure if there are any libraries that I can use without reinventing the wheel.


Thanks for your answers

Replies

I can’t speak to the state of MQTT libraries, but I can address the issue of servers in general.

It’s possible for an iOS app to include a server component but running that server in the background is not possible in the general case. For a server to work the app must not be suspended (see Technote 2277 Networking and Multitasking for more background on this). iOS provides no general-purpose mechanism for an app to run indefinitely in the background, and thus no easy way to run a server reliably.

So, if your app is running indefinitely in the background for some other reason, implementing a server within your app should be straightforward. But for most apps, which get suspended shortly after moving to the background, implementing a server that runs while they’re in the background is not feasible.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"