3

I am currently working on Parse integration for one of my iOS applications where in I need to pull some records (Customer Feedback from existing table) from Parse and show them in mob-app.With Parse iOS SDK 1.6.1 I realized that I could also use LocalDataStore to provide include the offline support, however going through the following articles appCoda , raywenderlich and Parse documents I could not figure out a solution which could solve the use case I am dealing with.

Step 1: Show all records pulling from server (Initially Sync - but I also realized that I need to enable [Parse enableLocalDatastore]; which is now interfering with initial data pull )

Step 2: Allow user to perform certain modification and sync this data back with server.

Step 3:Keep the local data store in sync with online data all the time (provided I have internet as and when needed).

I was able to implement the ALL-ONLINE version of the app and achieve all features as needed but I would also like to include the Offline support. A few question that raises doubt are

  1. does LocalDataStore only support offline usage of the application that has to be manually synced with Parse backend ?
  2. The data fetch from Parse localDataStore via [query fromLocalDatastore]; doesn't return anything on first call (I know because there isn't anything on device). Do I need to write the logic to pull down data from backend every time and keep local datastore in sync ?)

Can someone correct me if I am using it the wrong way? or give me some pointers for correct usage, then it will be really helpful.

Rahul Sharma
  • 3,013
  • 1
  • 20
  • 47

1 Answers1

4

Yes, you have to query the data online first(without "[query fromLocalDatastore];"). And "pin' it for local usage. Usefull hint can be to use "UpdatedAt" to get only the new stuff.

Once done, you can get data online and offline. The sync should be automatic.

'Red flag' : Don't forget to update to sdk 1.6.2, as they solve a lot of big bugs related to LocalDataStore.

Franck
  • 8,939
  • 8
  • 39
  • 57
  • Does that also mean that once initial set of data has been fetched I can freely use [query fromLocalDatastore]; without worrying about the underlying datastore getting synced from online service behind the scene. What I don't want to do is to manually keep a track of updated objects at both online and Offline ends and syncing them manually.Another problem that I see is when there are thousands of records available online on first data pull, not all of which are queried on first run and thus I might loose remaining objects because of a new value for updatedAt :( – Rahul Sharma Jan 26 '15 at 21:04
  • hi You can get new object and 'pin' it. After, yes, you can [query fromLocalDatastore]; to get all datas. I have asked a question on parse forum, to see if we can do this in one operation (sync a PFQuery). No answer. I suggest you to also ask. :) https://groups.google.com/forum/#!topic/parse-developers/YxA3N1ugz7E – Franck Feb 11 '15 at 13:12
  • shouldnt you look at the local store first ? If there is no network then your call to the localstore never occurs – DogCoffee Apr 03 '15 at 00:21
  • Franck, thanks for explaining the way to handle updating between local and remote. I've been developing around this now, and it helps a lot. However, how do you handle "deleted" objects when you update data? Deleted objects from other devices will remain in local datastore if you query with udpatedAt. – Umeumeume Aug 01 '15 at 05:27
  • Seems like soft delete is a way. http://stackoverflow.com/questions/27779865/parse-com-find-deleted-objects – Umeumeume Aug 01 '15 at 23:21
  • Non Umemoto: create a date column named "deletedAt". When you query data, exclude data who have a "deletedAt"value. The downside are that the deleted data will stay on the DB. (feel free to nil all the values to save space). – Franck Aug 31 '15 at 12:11
  • How exactly is new data to come in from the server? Do you need to query for it manually (using perhaps UpdatedAt to only pull things that have been added/updated/deleted?)? If you need this to happen in real-time do you need to implement extra logic (WebSockets, Pusher etc.) to achieve this? – Marchy Jan 27 '16 at 01:30