I'm writing an app for a client where the users will enter data during the day, then at a given point at night (say, at midnight) the user's data for that day should upload to the server.
Therefore I need to schedule a method to run on my app at midnight, even if the app is in the background. This method will then sync the collected data with the server and download any changes.
In order to achieve this, I imagine I need to set the app to always run in the background (i.e. longer than 10 minutes) then schedule the function to run after a specific time. Do I do this by using performSelector: withDelay:
? Or do I need something more robust because the app will be in the background?
Thanks guys!
So here’s what happens: The system resumes (or relaunches) your app in the background because the user enters your region. You schedule a timer for 3 minutes and start a background task to prevent the app from being suspended. After 30 seconds the background task expires.
Request the system to launch your app in the background to run tasks. Use the BackgroundTasks framework to keep your app content up to date and run tasks requiring minutes to complete while your app is in the background. Longer tasks can optionally require a powered device and network connectivity.
Register launch handlers for tasks when the app launches and schedule them as required. The system will launch your app in the background and execute the tasks. A class for scheduling task requests that launch your app in the background. Use the debugger during development to start tasks and to terminate them before completion.
BackgroundTasks is a new framework introduced in iOS 13 to offer developers more ways to execute background work. Background task offers two type of classes: BGAppRefreshTask: To refresh your app in the background periodically and always have up to date content.
You might check out UILocalNotifications. You could schedule that event to happen and then set a badge icon to let the user know it processed something (or not).
Info on these HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With