ionic framework sync data and work offline

流过昼夜 提交于 2019-12-02 21:18:14

PouchDb is sure a good solution to provide data synchronization to your app. But depending from what you need to do you could choose between several PaaS that provide natively data synchronization and offline capabilities(along with many other features like oAuth2 authentication and push notification).

I have worked with a few i can suggest:

  1. Parse
  2. Firebase
  3. Microsoft Azure mobile services

All these platforms provide clients to work with for all native mobile environments and javascript.

Depending on the amount of data you wish to cache, you can save it in local storage.

The logic would be like this:

  1. Make an $http request to your API
  2. In the .success stringify the response and store in local storage
  3. In the .error parse the stored local storage response
  4. Populate the same $scope variable from both the .success and .error

This way if your requests succeed (the device has internet and the API is functional) the data is stored. Otherwise, the requests fail (no internet or other reason), use the stored data.

An example of this can be seen here:

https://blog.nraboy.com/2014/06/saving-data-with-ionicframework/

However, like mentioned in a previous answer, PouchDB is a great option if you have a CouchDB database setup. Here are a few Ionic tutorials for syncing solutions:

https://blog.nraboy.com/2014/12/syncing-data-firebase-using-ionic-framework/ http://devgirl.org/2014/12/30/sync-data-using-pouchdb-in-your-ionic-framework-app/

Regards,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!