Keep ios app running in background forever

The story is the ios app, that I'm working on using react native, needs to keep running in background to receive silent notifications from the Backend then it will schedule local notifications using data from those silent notifications received.

Actually, in native code (objC), i'm using ios background modes listening for receiving remote notifications event to receive the silent notification while app in fore/background. I also tried the BGTaskRefresh (available from iOS 13+). It seems working fine if the app in fore/background. However, if the user swipes the app up in app switcher (a.k. force quit/kill the app), it stopped working.

So, please advise how to achieve the above feature. Or is there a way for the app to keep receving the silent notification and trigger didReceiveRemoteNotification method (appDelegate.m) even if it's kill or terminated by user/system?

Answered by Engineer in 677801022

The short answer to all your questions is No!

The long answer will depend what you are trying to accomplish with all this. There is no way to guarantee that your app will receive all silent notifications. If you need to execute some code to process every incoming notification, I suggest looking into using a notification service extension as discussed at https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension.

The Notification Service Extension will be executed for every visible push notification. So, it could serve your needs, as long as the user has not disabled the visibility of your notifications through various settings. The service extension will not be executed for push notifications that will not be presented visually.

Probably you can't monitoring background tasks, when app was removed from cache.

Yup I know, but i'm still looking for a workaround, is there a way to implement a background service that never dies in iOS ?

Accepted Answer

The short answer to all your questions is No!

The long answer will depend what you are trying to accomplish with all this. There is no way to guarantee that your app will receive all silent notifications. If you need to execute some code to process every incoming notification, I suggest looking into using a notification service extension as discussed at https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension.

The Notification Service Extension will be executed for every visible push notification. So, it could serve your needs, as long as the user has not disabled the visibility of your notifications through various settings. The service extension will not be executed for push notifications that will not be presented visually.

You could also consider adding a user education feature within the app to explain that if the user wishes for the app to run in the background, they should not force quit it from the app switcher.

Thanks Gualtier Malde! Regarding to your answer, I'm trying to add a notification service extension to my app. Hooking to didReceiveNotificationRequest event, then check for a pre-defined title/body string to surpress/cancel user notification to be presented using com.apple.developer.usernotifications.filtering entitlement as stated in below thread https://developer.apple.com/forums/thread/661320 May that posible @Malde ?

Besides, the solution i mentioned in my previous comment above is only applicable for iOS 13.3+. How about older ios? Any workaround to be applied for the same result ?

Keep ios app running in background forever
 
 
Q