Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule an iOS app task to run while in the background

Tags:

ios

background

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!

like image 923
theDuncs Avatar asked May 19 '12 10:05

theDuncs


People also ask

Why is my app running in the background for 3 minutes?

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.

How do I run tasks in the background of my App?

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.

How to launch an app in the background during development?

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.

What is backgroundtasks in iOS 13?

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.


1 Answers

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

like image 67
LJ Wilson Avatar answered Sep 22 '22 11:09

LJ Wilson