Updating Parse Local Storage Only

We are currently planning to develop an iOS application that displays the list of products for viewing by the user in the form of a list with the corresponding small PDF file, and we want to use Parse to store data, since we can easily log into the system Parsing and updating product information.

I am currently struggling with parsing documentation, when the application starts, we want it to query PFObject and get all the lines inside our class to store them locally using

[PFObject pinAllInBackground:objects]; 

Our application will also need to check and update this data warehouse in future launches to ensure that the latest product information is available.

When the user browses the list of products, we request a local data store to show the data so that the application works completely offline.

What I'm struggling with is how to clear or update the local cache when I restart, users will not make any changes to this local data, and I was thinking about using

  [PFObject unpinAllInBackground:objects]; 

But when we do this, followed by a request to bind the entire local data store, it is empty.

Thanks Aaron

+5
source share
2 answers

I managed to solve this problem myself as follows: now it works in the background thread and first disables all objects of the class, followed by fetching and binding of all objects.

 - (void)updateParseCacheForClass:(NSString *)className { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ PFQuery *query = [PFQuery queryWithClassName:className]; [query fromLocalDatastore]; NSArray *objects = [query findObjects]; if (objects) { [PFObject unpinAll:objects]; } PFQuery *query2 = [PFQuery queryWithClassName:className]; NSArray *objects2 = [query2 findObjects]; if (objects2) { [PFObject pinAll:objects2]; NSLog(@"Successfully retrieved %lu records. for %@", (unsigned long)objects.count, className); } }); } 
+3
source

I would like to make @MonkeyBlue code a bit smaller.

 - (void)updateParseCacheForClass:(NSString *)className { PFQuery *query = [PFQuery queryWithClassName:className]; NSArray *objects = [query findObjects]; [PFObject pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) { if(succeeded) { NSLog(@"Successfully retrieved %lu records. for %@", (unsigned long)objects.count, className); } else if (error) { NSLog(@"Error"); } }]; } 

The -pin; The method does synchronization automatically for you, so you don’t worry about duplicating objects. This is a cool parsing feature.

There are different versions of -pin; methods are available that may be useful.

 //for pining single object - (BOOL)pin - (BOOL)pin:(NSError **)error; - (BOOL)pinWithName:(NSString *)name; - (BOOL)pinWithName:(NSString *)name error:(NSError **)error; - (BFTask *)pinInBackground; - (void)pinInBackgroundWithBlock:(PF_NULLABLE PFBooleanResultBlock)block; - (BFTask *)pinInBackgroundWithName:(NSString *)name; - (void)pinInBackgroundWithName:(NSString *)name block:(PF_NULLABLE PFBooleanResultBlock)block; //for pining array of objects + (BOOL)pinAll:(PF_NULLABLE NSArray *)objects; + (BOOL)pinAll:(PF_NULLABLE NSArray *)objects error:(NSError **)error; + (BOOL)pinAll:(PF_NULLABLE NSArray *)objects withName:(NSString *)name; + (BOOL)pinAll:(PF_NULLABLE NSArray *)objects withName:(NSString *)name error:(NSError **)error; + (BFTask *)pinAllInBackground:(PF_NULLABLE NSArray *)objects; + (void)pinAllInBackground:(PF_NULLABLE NSArray *)objects block:(PF_NULLABLE PFBooleanResultBlock)block; + (BFTask *)pinAllInBackground:(PF_NULLABLE NSArray *)objects withName:(NSString *)name; + (void)pinAllInBackground:(PF_NULLABLE NSArray *)objects withName:(NSString *)name block:(PF_NULLABLE PFBooleanResultBlock)block; 
+1
source

All Articles