I am using PFFile to store images. If the image is already downloaded, I want to access it directly. If not, I want to use the background methods. However, if I use getData
, I get the following warning:
Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
Since I know that the data is available, this warning is unnecessary and clutters my log. Is there any way to access PFFile's data without triggering a warning?
You are getting the warning because the data is not available locally and getData is a synchronous call to fetch the data from the server. When getData is called, it blocks the main thread - the UI - and stops all app interaction until the data downloads, which is why you are getting the error. Generally, blocking the UI to do a background operation, such as downloading, is very much frowned upon.
I would use the isDataAvailable
property of PFFile to check if the data is available locally. If it isn't, use getDataInBackgroundWithBlock:
to fetch the data in the background. You can use the completion method supplied by that call to update your imageView.
UPDATE - You can also wrap the getData
call in a dispatch_async
block, which will move the operation to another thread, therefore removing it from the main thread and getting rid of the warning.