Manage iPhone app both online and offline

别等时光非礼了梦想. 提交于 2019-12-22 10:27:44

问题


I am stuck to a point, I am managing my app offline also. first time i get all profile data from a webservices and store its path into sqlite, I am facing problem in updating those data, like if images are changed how should I notify into my app, I searched it on Google and only solution is to send push notification to app when record is updated. What if user do not allow push notification?

Is there any other solution to manage app offline and update only when record is changed from online database?


回答1:


implement offline mode in application

  • put one extra column data_status in all table That indicate data is entered in local database is in offline or online mode. 1 for online and 0 for offline
  • call API every-time with last response date and time on some frequent time interval(if required to update data frequent otherwise call when need) and API respond only changed or new data

when application is online

  • call API and Store data in local data base with data_status = 1 and then display that data on screen from local database
  • now when call again same API with server API response time and date and API respond only changed or new data.

when application is offline

  • check app is offline then skip API calling function and fetch data from local database.
  • now, when action perform on data like update insert. make that row data_status = 0
  • when internet come check local data base which data is with data_status = 0 and call web service according that one by one, and getting success of each API make data_status = 1 and update row in local database.

Thank you




回答2:


I would suggest to give Image Name base on timestamp and unique userId. like as below.

ImageName = yourUserId_timestamp.(111_1234567).

So Image name always be unique. so when you fetch date from server. first check that image is already exist in data base or not. if it is not then update image name with help of userId and store it. if it is then leave it.

Thanks




回答3:


Nothing to change from your (application) side, your server guy can handle this flow. Whenever a new image will be upload, a new URL will be generated that you will for particular object. You can replace it in your local (simply update existing data).




回答4:


You can use API's to check version of data cached in App. If updated version is available on server then you have to update local data with updated server data.



来源:https://stackoverflow.com/questions/35473393/manage-iphone-app-both-online-and-offline

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