Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

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?

Upvotes: 14

Views: 1248

Answers (1)

pds
pds

Reputation: 322

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.

Upvotes: 7

Related Questions