简体   繁体   中英

Parse local Datastore not refreshing after new PFQuery

I am testing out Parse localDatastore and am struggling with refreshing the local datastore after a new server PFQuery.

The PFQuery works fine and seems to pin the array to the local datastore just fine. When I change the contents of the array on the server, the server PFQuery pulls down the updated array, but the local datastore doesn't seem to update:

- (void)viewDidLoad {
[super viewDidLoad];

// Query Parse
PFQuery *query = [PFQuery queryWithClassName:@"contacts"];
NSArray *objects = [query findObjects];
[PFObject pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) {
    if(succeeded) {
        NSLog(@"Successfully retrieved %lu records from Parse.", (unsigned long)objects.count);
    } else if (error) {
        NSLog(@"Error");
    }
}];
}

and then a UIButton is used to log the contents of the local datastore to the console:

-(IBAction)showDatastore {

// Query the Local Datastore
PFQuery *query = [PFQuery queryWithClassName:@"contacts"];
[query fromLocalDatastore];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        NSLog(@"Successfully retrieved %lu contacts from Datastore.", (unsigned long)objects.count);
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}]; 
}

In my sample the original array has 15 objects. Both the count's from each array initially are 15. I then remove an object from the server array and the initial PFQuery count is 14, but the local datastore count remains 15.

Parse's documentation states:

When an object is pinned, every time you update it by fetching or saving new data, the copy in the local datastore will be updated automatically.

But that doesn't seem to be the case... at least not with this recommended code. Is there something i'm missing?

It depends on how you are deleting the object. If you're using deleteEventually , then the deletion will propagate to the LDS

You can query from the local datastore using exactly the same kinds of queries you use over the network. The results will include every object that matches the query that's been pinned to your device. The query even takes into account any changes you've made to the object that haven't yet been saved to the cloud. For example, if you call deleteEventually, on an object, it will no longer be returned from these queries.

But any other method requires explicit unpinning if you want it to work.

deleteEventually is the prefered method I believe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM