IOS-Parse.com Synchronization of multiple devices with local data storage

I am trying to use local-datastore with iOS.

Say I have two or more devices.

I use saveEventually to save data locally (and in the cloud). When working on only one device, it works great.

When I start working with several devices, for synchronization I use:

PFQuery *query = [UserPreference query];
[query whereKey:@"userId" equalTo: [PFUser currentUser].objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 
if(!error){
    [UserPreference pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) {<---- objects here are fine
    if(succeeded){
     [query fromLocalDatastore];
     NSLog(@"Local %@", [(UserPreference*)[[query findObjects] objectAtIndex:0] filterContext ]); <--- however here the old value is retrieved
     }
   }];
  }
}];

So, I get the proper objects from the cloud, then I PinAll, but when I retrieve from localDataStore, are the old values ​​retrieved?

Could someone please be kind enough to explain: 1. if at all possible, then for synchronization between two devices using local data storage 2. What am I doing wrong?

PS: I notice that serverData in the objects contains the correct information, but does not update the object

+4
2

, . , , , . pinWithName:

  PFQuery *query = [UserPreference query];
[query whereKey:@"userId" equalTo: [PFUser currentUser].objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if(!error){
        [UserPreference unpinAllObjectsInBackgroundWithName:@"userPreference" block:^(BOOL succeeded, NSError *error) {
                [UserPreference pinAllInBackground:objects withName:@"userPreference"];
        }];
    }
+3

, , , .

. , , . , , .

:

[PFUser logInWithUsernameInBackground:user password:pass block:^(PFUser *user, NSError *error) {
if (user) { /* success, user object is in local datastore */ }
}];

, . , , . , , , , , . :

PFQuery *query = [PFQuery queryWithClassName:@"History"];
[query whereKey:@"user" equalTo:[PFUser currentUser]];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if(!error){
        NSLog(@"Fetched %lu objects", (unsigned long)[objects count]);
        for (PFObject* item in objects)
            [item pinInBackground];
    } else {
        NSLog(@"Parse error pulling data after login: %@ %@", error, [error userInfo]);
    }
}];

, , . , , , , . , .

+1

All Articles