1

I am asking this question because I didn't found any resources on this issue, and therefore I can't complete my project on this.

I have this basic alamofire post request:

let request = Alamofire.request("https://httpbin.org/post", method: .post, parameters: parameters, encoding: JSONEncoding.default)

If I am not connected to the Internet, I want to save this request and then perform it again when the internet is connected.

Any ideas on how to start on this issue? Any suggestion will be very much appreciated.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Creative crypter
  • 1,348
  • 6
  • 30
  • 67
  • I may be missing something, but surely all you need to do is manage a text file in JSON format that stores the parameters for any outstanding requests that you can't carry out immediately. When connectivity is restored, read in the request parameters from the file to create the requests, and delete the entries that successfully execute. – Marcus Sep 17 '17 at 18:39
  • and how should i save a swift "variable" to a text file? – Creative crypter Sep 17 '17 at 18:43
  • Take a look at the Apple docs on JSONSerialization: https://developer.apple.com/documentation/foundation/jsonserialization. You essentially want to convert the JSON to a Data object that you can then write to file and read back in later. But also take a look at the posted answer that has crossed with my comment. – Marcus Sep 17 '17 at 18:47

1 Answers1

0
  1. With the help of this answer determine if there is working internet connection or not.

  2. case when there is no internet connection
    Save your post parameters in your user default or file

  3. Follow this answer to get to know when iphone is again connected to internet.

  4. with the help of answer linked in step 2 read your parameters from file and make the post request

Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89