Keep socket open in background?

Hi,


I'm working on an app that uses an XMPP client library, which I believe is based on TCP sockets.


When the app is running, it can get callbacks from the XMPP code to alert it of incoming messages. Of course, this stops working when the app goes into the background or the phone locks.


Is there any way to keep this working in the background? Ideally we'd like to be able to receive an XMPP message and if the app is not in the foreground, we'd post a local notification.


You may be wondering why we don't just use push notifications. The answer is because the app we're building is going to be used in a medical facility, and the customer wants to restrict it to a private LAN with no internet access (the XMPP server is on the LAN). Therefore we won't be able to receive or send messages through APNS.


The app will not go into the app store, it will be distributed through enterprise distribution. We're hoping that this allows us some more flexibility with background processing.


We know that apps can play audio continuously in the background and we had the idea that we might be able to play a silent audio stream to keep our app alive, but we think this is a hack and would prefer a better solution.


Thanks,

Frank

Hello Frank,

There is a specific category for background apps that need to fetch new content. It looks like it is a pull rather than a push.


If you have an enterprise account, you can do what you want. Use a DTS ticket.

If you have an enterprise account, you can do what you want.

That is not true. While Enterprise developers can build apps that don’t go through App Review, they are still constrained by the various legal agreements. I’m not a lawyer, so I’m not going to offer any interpretation of what those constraints are, but they do exist.

Share and Enjoy

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

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

Let’s start with some basics. Technote 2277 Networking and Multitasking discusses the default behaviour of networking in the background. You should read it through because I’m going to assume its terminology.

iOS provides no general purpose way for a networking app to keep ‘*****’ TCP connections alive when the app is suspended. The only mechanism that has ever existed for this was the legacy VoIP architecture, but that has a number of limitations:

  • App Review requires that it only be used for VoIP

  • It’s been formally deprecated for a number of releases now

  • iOS 10 and later limit access to this API (see QA1938 iOS 10 and the Legacy VoIP Architecture)

If I were in your shoes I’d negotiate with your customer to use push notifications for this. That would require them to open up their network slightly, enough to allow two types of outgoing connections:

  • From the iOS devices to the APNs servers

  • From your push provider (your XMPP server) to the APNs servers

Both of these can be very tightly controlled based on:

  • Outgoing, not incoming

  • The IP address — The APNs servers are on Apple’s network, that is, 17/8.

  • Port number — I don’t remember those off the top of my head but I know that they are officially documented.

If you can’t do that then, yes, you’re definitely off in the land of unsupported hackery. In that case my only concrete advice is that you file an enhancement request that describes your requirements and what you’d like to see added to the system to resolve them.

Please post your bug number, just for the record.

Share and Enjoy

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

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

Such as? I'm not asking for legal interpretations. Can you specifically say what these agreements are so that someone could find them and get a legal interpretation of what restrictions still apply to enterprise distribution?


The OP is talking about a medical facility, not a crypto-currency or gambling app. Their network restrictions may be due to their own legal and regulatory requirements. I would hope that Apple DTS would be able to provide a workable solution. I'm pretty sure they could do this months or years before an enhancement request ever gets fulfilled.

Keep socket open in background?
 
 
Q