-1

I'm developing an App that communicates with a local Web Server and receives data from it (though WebSockets or HTTP) without using internet connection.

So I need to find a way to receive push notifications from the server without using Apple Push Notifications service even with the iPhone in standby so the notifications show up on Apple Watch. For example my idea is to send data from the server to the iPhone client and then creating the notification locally. In order to do so I need to run my app in Background but the modes I found couldn't help me.

-Run an arbitrary piece of code: i can run the app for maximum 3 minutes in background after pressing Home for example. I need to have the app executing in background "forever" if possible in order to receive data from the server and process it.

-Background fetch: this mode isn't reliable because i cannot control when my code is being executed but it's iOS that decides based on the user's behavior and other conditions.

I read about Silent Push Notifications, VOIP (PushKit) but i didn't understand if you need APNs to make them work.

Also does this article describe Silent Push Notifications? https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app#see-also

If yes, then I cannot use Silent Push Notifications more than 2/3 times per hour, plus it's considered low-priority, not reliable...

Here it says that from iOS13 i cannot use VOIP mode anymore for non VOIP Apps: Can I use PushKit to do regular push with out using VoIP? Will it allow killed app to be launched in background if user does not act on notification?

Are there some ways to bypass APNs if you can't access the Internet and wake up an app in background based on an event?

Thanks :)

JackieNBee
  • 173
  • 3
  • 18

1 Answers1

0

All PushNotifications (including silent) are delivered through APNs, no exception. They need an internet connection in order to work. All are considered "Best effort" and offer no guarantees. If the client is not online, 1 notification per app will be cached and attempted to be delivered when the user next has a connection. If another notification comes into APNs while one is cached, the first will be deleted and never be sent to the user.

The ones you create locally are called LocalNotifications and obviously don't require an internet connection.

You could use Silent notifications to trigger an app to wake up and do a short amount of work, and perhaps then fire a local notification if necessary. But as you mention there are limitations to how often you can use it and still no guarantees.

There is no way to keep an app running in the background forever. Running networking code in the background is extremely draining on the battery and is blocked for that reason. The modes you are referring too are the only way (without jailbreaking) to do this. The only option to run code in the background is using background app refresh, requesting 30 seconds of time every X (where X is decided by the system, could be minutes, could be hours, could be days ... depending on the users usage of your app and others). Background app refresh can also be disabled per app in iOS settings.

I'm not sure what your use case is, but the functionality you have described is not possible. I don't know if using an SMS gateway to send text messages instead is an option as those will have higher SLA's and won't require an internet connection. But unlike APNs, its not free.

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56