I am currently programming an app that should work offline. The data should be synchronized periodically in the background. Most of the data only needs to be loaded from the server. A few also need to be sent to the server.
My first thought for synchronization was to use the BackgroundTask framework. So to use several BGAppRefreshTaskRequest for the synchronization. Several, because the data is refreshed with different frequency.
Since the normal background URLSession does not work when the request is started via a Background Task the request has to be executed via a Background URLSession. Is this correct? I've found different information about this, so sometimes it's said that normal requests without a background session also work.
The main problem with the application is that the user authenticates via OAuth and the token is only valid for one hour. After that, the token has to be renewed. Is this possible with the Background URLSession? My idea now was to check for a 401 error on the DownloadTask and then initialize a token refresh, once successful retry the original request. This would all run through the Background URLSession. However, since the system schedules and executes the requests I wonder if this would even work in this constellation.
Maybe there are other ways to implement synchronization. What would be the best approach here?
Thanks,
Lars
My first thought for synchronization was to use the BackgroundTask framework. So to use several BGAppRefreshTaskRequest for the synchronization. Several, because the data is refreshed with different frequency.
Since the normal background URLSession does not work when the request is started via a Background Task the request has to be executed via a Background URLSession. Is this correct? I've found different information about this, so sometimes it's said that normal requests without a background session also work.
The main problem with the application is that the user authenticates via OAuth and the token is only valid for one hour. After that, the token has to be renewed. Is this possible with the Background URLSession? My idea now was to check for a 401 error on the DownloadTask and then initialize a token refresh, once successful retry the original request. This would all run through the Background URLSession. However, since the system schedules and executes the requests I wonder if this would even work in this constellation.
Maybe there are other ways to implement synchronization. What would be the best approach here?
Thanks,
Lars