I have a VPN-Client app that asks the user to pause the connection for 5, 30, and 120 Minutes. The user probably leaves the application to do some work outside of my app in this period, therefore I need to Reconnect the app even if is in the background.
I tested these ways:
UIApplication.shared.beginBackgroundTask
: It only leaves the app unsuspended for 30 seconds.DispatchQueue.global(qos: .background).asyncAfter
: It waits to app enter the foreground to toggle.Thread.sleep
in Background Thread: This waits to launch as DispatchQueueLocal Notification
: Unfortunately it does not support silent mode as APNS.
My problem with possible ways:
- Using
APNS
and Scheduled Push Notification` to send a silent message: This way probably works, but I prefer to handle it without a server. - Using
Background Fetch
fromCapabilities
in Background Modes: I searched a lot about this, and I think it was used for background app refresh and cycling tasks that should be run every day, hour, etc. Therefore, my case can't be used, or it's not efficient at all. - Using
Background processing
fromCapabilities
in Background Modes: I searched a lot about this too, I didn't quite catch that it can be used once, or this should be used in a cyclic way as Background Fetch. and my task to reconnect is not that heavy and long to use this strict feature that many times apple mentioned using alternative ways if possible.