Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A long-running operation is being executed on the main thread warning on regular Parse functions

First of all, I know what this means. The problem is that I'm getting this error on standard calls that can't be converted to background calls. I'm getting this error on app start at:

[Parse enableLocalDatastore];

PFInstallation *currentInstallation = [PFInstallation currentInstallation];

I've found out that these methods are causing the trouble by setting a symbolic breakpoint on warnParseOperationOnMainThread and examining the call stack.

I can't replace these calls with async ones, and as far as I know, these methods are meant to be called regularly from the main thread. Is this a Parse bug, or should I call all these methods from a background thread?

like image 203
Can Poyrazoğlu Avatar asked Dec 13 '14 18:12

Can Poyrazoğlu


1 Answers

Wrap the calls in...

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];

        dispatch_async(dispatch_get_main_queue(), ^(void){
            // any UI updates need to happen in here back on the main thread
        });
})

and you will no longer see the warnings.

like image 84
pds Avatar answered Oct 19 '22 05:10

pds