1

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!

Taras Tomchuk
  • 331
  • 7
  • 19
  • What are you using on backend? I mean are you using your own web services are some third party like firebase, azure etc ? – Imran Khan Sep 28 '18 at 10:03
  • @Napster I'm using my own services – Taras Tomchuk Sep 28 '18 at 10:27
  • 1
    Okay. If you want your app to work in both offline and online modes then you have to save data locally (Core data, files etc) and when you are connected to internet you will upload local data to your server in background. – Imran Khan Sep 28 '18 at 11:21
  • And if you use google firebase then it will 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. Microsoft azure is a good option if you have a relational database. – Imran Khan Sep 28 '18 at 11:26
  • @Napster Ok, thanks for your advice. I think I'll go with saving these products in Core data for now – Taras Tomchuk Sep 28 '18 at 11:43
  • I have answered your question with our above comments. If you agree please accept. Thanks – Imran Khan Sep 28 '18 at 11:57
  • @Napster done, thanks for you suggestions! – Taras Tomchuk Sep 28 '18 at 11:58

1 Answers1

1

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
Imran Khan
  • 317
  • 3
  • 17