Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isDataAvailable causing warnParseOperationOnMainThread() Parse.com

When you call getData on a PFFile, if isDataAvailable returns true then this should not cause the a blocking operation to be executed, right?

I'm getting the following warning: Warning: A long-running Parse operation is being executed on the main thread. when doing something like

if (isDataAvailable) 
   [... getData];

but I still get the warning.

like image 371
Apollo Avatar asked May 02 '26 22:05

Apollo


1 Answers

Warning: A long-running Parse operation is being executed on the main thread.

is sent because parse wants to warn you that you shouldn't execute heavy operations like getting data on the main thread. This could cause UI complications, and it risks getting rejected based on poor UX.

You should be running

[yourPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if (!error) {
        // data available here, put any operations dependent on the data existing here
    }
    else {
        // notify user that there was an error getting file, or handle error
    }
}];

With this, parse checks first to see if the data is available before downloading new data. That way you can avoid checking isDataAvailable in your code and it won't block the main thread if there's a shotty connection or a large file.

like image 163
Logan Avatar answered May 04 '26 12:05

Logan