Reputation: 55
Need Help!!!
Guys, i am using Parse for cloud data backend for my app. Have a parse class with column type as file. It stores images. In my application i need to fetch all images available in this column and store in a array.
Next is the error and code sample. Per my understanding it fails on findObjectsInBackgroundWithBlock. Please help
Error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This query has an outstanding network connection. You have to wait until it's done.’
Code:
(PFQuery *)queryForTable { NSLog(@"queryForTable *ENTER ");
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; [query whereKey:TAB_PARSE_WHERE_KEY equalTo:self.tShelfID];
// If no objects are loaded in memory, we look to the cache first to fill the table // and then subsequently do a query against the network. if ([self.objects count] == 0) { query.cachePolicy = kPFCachePolicyCacheThenNetwork; }
NSLog(@"queryForTable *** 1 ** ");
[query cancel]; //cancels the current network request being made by this query (if any) [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"queryForTable *** 2 ** ");
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved ");
//for (PFObject *object in objects) {
//NSLog(@"INSIDE FOR LOOOP");
//NSLog(@"%@", object.bookId);
//}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
//[query orderByAscending:TAB_PARSE_ORDER_KEY];
NSLog(@"queryForTable *EXIT "); return query;
}
Upvotes: 0
Views: 188
Reputation: 2848
To download file from parse
First you need to call simple query to download all image reference and then you need to use PFFile class of parse.com
Please check out this link : https://parse.com/docs/ios/api/Classes/PFFile.html
You can write below code in some function to download files from parse.
PFQuery *query = [PFQuery queryWithClassName:@"Your Classname"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *currentObj in objects) {
PFFile *currentFile = [currentObj objectForKey:@"Your column name in which files are stored"];
// TO DOWNLOAD SYNCHRONOSLY
NSData *fileData = [currentFile getData];
UIImage *img = [UIImage imageWithData:fileData];
//--------- You can store IMG object ref in your array and display --------//
//TO DOWNLOAD ASYNCHRONOSLY
[currentFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
//--------- You can store IMG object ref in your array and display --------//
UIImage *img = [UIImage imageWithData:data];
}
} progressBlock:^(int percentDone) {
NSLog(@"Download Complete Percentage");
}];
}
}
}];
Upvotes: 0