How to store ParseObject in both local datastore and Parse Cloud on Objective-C iOs 8?

I would like to store all my objects both locally and in the cloud and only read from the Local Datastore. All my objects should be saved in both local and online store, and the local data store should be in sync with Parse Cloud.

I want my app to work offline so I can use it everywhere, but by keeping all data in the cloud as fast as possible, NetConnection is available!

thank

+3


source to share


1 answer


First of all you need to enable the use of local data storage:

[Parse enableLocalDatastore];

      

Then I always save the new PFObject to local datastore using

PFObject *userStat;
[userStat saveEventually];

      

This will bind your object to local data storage and store it in the cloud (eventually). If you want to reset all of your locally saved data to what you have in the cloud, you can; unplug all your local objects first and then fetch all remote objects and copy them locally:



[PFObject unpinAllObjects];
PFQuery *query = [PFQuery queryWithClassName:@"UserStats"];
[query whereKey:@"parent" matchesQuery:query];

    return [[query findObjectsInBackground] continueWithBlock:^id(BFTask *task) {
        if (task.error){
             return nil;
        }
         return [[PFObject pinAllInBackground:task.result]     continueWithBlock:^id(BFTask *task) {
            return task;
        }];
}];

      

Local queries can be done using:

 [query fromLocalDatastore];

      

Parse has good documentation on these methods here .

+2


source







All Articles