Umesh Kolhe
Umesh Kolhe

Reputation: 55

Error while fetching an parse class column in NSArray in my ios app

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:

}

Upvotes: 0

Views: 188

Answers (1)

Malav Soni
Malav Soni

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

Related Questions