Periodic background synchronization

Im completely new to iOS programming and now I want to implement periodic background synchronization to synchronize my server data with client data. What I want to achieve is comparable to Androids SyncAdapter , where you can define a time interval (for example, every 30 minutes), and the system will automatically display a given task in the background.

So far, I have not been able to find such a mechanism for Swift 3.0, so I need to ask if anyone has any experience or any hints on me how I can achieve this.

What I want to do sounds pretty simple:

When the application launches for the first time, the application must set up a synchronization manager that automatically runs a background job every 30 minutes. The background task is responsible for synchronizing server and client data (using Alamofire).

How can i do this?

+4
source share
2 answers

There is an iOS feature called BackgroundFetch that you can configure to

regularly downloads and processes small amounts of content from the network.

You can configure minimumBackgroundFetchInterval .

Unlike the Android feature mentioned, this interval is not guaranteed.

The OS does some heuristic in the black box. It rewards you for using โ€œreasonableโ€ (for the OS) processor / power times, as well as for frequent user use. On the other hand, you get a penalty for draining the battery, worse if your application has never been used.

See: Apple Documentation


Alternatively, depending on your needs, you can publish Silent (push) Notification whenever user data changes on the server side. A silent push awakens your application without notifying the user, so you can receive data and possibly inform the user by planning a local notification.

See: Apple Documentation

+6
source

You can not. Apple does not allow third-party applications to have regular background time. You will need to come up with a different approach, for example, implement a quiet push notification from your server when new content is available.

+1
source

Source: https://habr.com/ru/post/1012082/


All Articles