简体   繁体   中英

Save Alamofire upload with multipartFormData request Swift

I need to create an offline mode in my app.

User should be able to create new product with images and text data and send to server both in online and offline modes. Right now it works in online mode, but as for offline I need help. As far as I understand, here is what I should do:

  • Check Internet availability - done.
  • If no Internet connection - save Alamofire request and send it when there is Internet - how to?
  • Clear saved requests that were sent successfully.

How should I save multiple Alamofire upload with multipartFormData requests?

I have found this answer - SO Answer but it covers only simple post request without any files and my case is a bit complicated.

Would be grateful for code examples or any steps of how to save requests.

Here's how I'm checking Internet:

if Reachability.isConnectedToNetwork() {
        print("Internet Connection Available!")
    } else {
        print("Internet Connection not Available!")
    }

And in my class Reachability I'm checking for Internet connection.

Many thanks in advance for your help!

For your app to work in both online and offline modes, there are multiple options but I will mention some of them.

  • Save data locally (Core data, files etc) and when you are connected to internet you will upload local data to your server in background.
  • Use Google Firebase. Implementation wise it will be very easy because firebase provides offline feature and you would not be doing any syncing work on your own. But keep in mind firebase does not have relational database it uses document base database.
  • You can also use Microsoft Azure.It is a good option if you have a relational database.
  • Amazon also provide sdk for offline data sync

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM