ios – WorkManager or Queue for URL Session for calling net apis in SwiftUI to sync knowledge solely when community is offered


Is there the idea of a WorkManager in SwiftUI like there may be in Android. The use case is syncing knowledge when there may be not a dependable community. On this use case I’ve a Core Information database on the iPhone/iPad and updates can occur and not using a community connection, however I need to replace the principle server by calling an online api when community connectivity is offered.

When a brand new file is created in iPhone Core Information, I need to queue up the change for when the community is offered and replace the native file with the outcomes. If there may be an error, I want to put it aside as effectively. Ideally I might have some management over frequency and variety of tries. I additionally don’t need it to strive if there isn’t any community.

I additionally need the queued request to persist even when the app shuts down.

For instance, utilizing my iPhone I create a brand new file in Core Information. The telephone shouldn’t be related to the community once I do, however the request is queued up, however doesn’t attempt to name the online api as a result of there isn’t any community. I shut down the app and open it up later in a special location the place there may be community service. The decision fails for some purpose and I shut down the app once more. I open the app later in an space the place there may be service and the online api name is tried once more and succeeds.

My present API calls appear to be this:

let (knowledge, response) = strive await URLSession.shared.knowledge(for: request)

if let response = response as? HTTPURLResponse {

    let json = strive decoder.decode(T.self, from: knowledge)


I’ve accomplished a lot of searches and maybe my phrases are unsuitable as a result of I’ve not been capable of finding this situation. I’m new to iOS so it is seemingly I am simply trying to find the unsuitable issues.

I’ve seen movies like this one on concurrency with URLSession but it surely appears to be a right away request working within the background and never a the precise scenario of community connectivity and persisting of the request. I noticed this submit but it surely was some time in the past and never answered.