0

I have a device, located in a Wi-Fi local network possibly without Internet connection, which sends notifications to the devices that are connected to it using a web-socket.

But when I lock the phone or press the home button, my application goes to background mode and the web-socket connection gets closed, so since then any notification doesn't get to the phone.

I know I can do this by using remote notifications (with Apple Push Notification Service), but my device is intended to work on any Wi-Fi network (with or without Internet access) or generating its own Wi-Fi access point (and therefore without Internet access).

So the question is: Is it possible to have a persistent connection, like in Android where I can maintain a connection in a background service?

Iván Pérez
  • 2,278
  • 1
  • 24
  • 49
  • 1
    It is if your app isn't intended for the App Store; you can use audio background mode and play "silence". If your app has to go in the App Store, then it isn't possible. An iOS device is not a server – Paulw11 Aug 23 '17 at 11:34
  • @Paulw11 The iOS device doesn't act as a server. The web-socket server is located on the external device that generates the notifications. My app connects to that server and keeps the connection always open. – Iván Pérez Aug 23 '17 at 11:37
  • 1
    What I meant by not being a "server" is that it doesn't support long-running background tasks. It is designed to optimise battery life by shutting down tasks when the user isn't actively running the app. – Paulw11 Aug 23 '17 at 11:39
  • In Android, you can keep another process running with or without main app. If you still needs to get data like websocket over iOS device when it is in background or terminated mode, then you can use Silent push notification ( Voip ) using payload you can schedule localnotification and your app will be active in terminated mode as well ( Max till local notification sound file plays , 30 seconds max ) and you can connect again to websocket or API and get data from server and utilise in iOS side code. – Hasya Sep 08 '17 at 08:07

1 Answers1

3

No, you can't if you want your app in the App Store.
If not (for example this is an Enterprise app), you can use kind of hacks, like silent audio or voip but this will drain battery a lot.

In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP).
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories

unlimited backgrounding on ios with silent audio
Apple docs - background execution

Adam Różyński
  • 451
  • 3
  • 10
  • "Apps that receive regular updates from external accessories" - Do you know if external accessories can connect to iOS devices using Wi-Fi? As far as I've read, those accessories can only connect using a cable or Bluetooth. But if using Wi-Fi is possible, maybe we can certificate it to be an external accessory and achieve what we need. – Iván Pérez Aug 24 '17 at 07:08
  • Don't know for sure, but I presume they writing about bluetooth 4.0 and lightning accesories. – Adam Różyński Aug 24 '17 at 08:15