I need something similar to Facebook's offline post capabilities. Basically I want users to create content locally on the device regardless of connection state, and whenever internet becomes available it should POST/PUT to the server.
I've searched the internet for a solution and I found that NSURLSessionUploadTask
can be used for POST-ing in the background. But I couldn't figure out if the following scenarios are supported:
First of all, background NSURLSession
allows file upload only. If that is ok for you:
application:handleEventsForBackgroundURLSession:completionHandler:
. After you process the signal and call the completion handler or 30 second timeout, the app will be closed.URLSession:task:didCompleteWithError:
There is a good tutorial on background NSURLSessions
. I suggest you to read all 4 parts of this great article.
If file upload is not an option for you, i suggest you to save information into local database and then wait for internet is reachable. (a good approach here is use of Reachability library, Alamofire allows to do that too). When internet becomes available, simply call your http requests with saved data.
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