14

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?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • Have you tried setting a symbolic breakpoint where the log states? Alternative implementation is suggested when the breakpoint fires. – soulshined Dec 13 '14 at 18:53
  • @soulshined of course I did, its how I found out which calls are causing the log. No, nothing is suggested other than setting the brealpoint. – Can Poyrazoğlu Dec 13 '14 at 18:57
  • 1
    Interesting to see being downvoted with no reason at all. People are really interesting these days... – Can Poyrazoğlu Dec 14 '14 at 21:01
  • Did you use any Cache Policy's methods? Disable it! – TonyMkenu Dec 14 '14 at 21:10
  • @TonyMkenu I *used to*. They result in immediate crash of the app anyway. – Can Poyrazoğlu Dec 14 '14 at 21:10
  • Have you tried to set a symbolic breakpoint .. but on `warnParseOperationOnMainThread` .. like here: http://stackoverflow.com/a/20989198/1702413 ?? – TonyMkenu Dec 14 '14 at 21:14
  • @TonyMkenu yes, see my comments above. (I'm also updating the question to reflect that) – Can Poyrazoğlu Dec 14 '14 at 21:28
  • for PFInstallation you can use: `currentInstallation saveInBackgroundWithBlock`; PFAnalytics `cache` the request and I think here is the Parse bug.. https://parse.com/docs/osx/api/Classes/PFAnalytics.html – TonyMkenu Dec 14 '14 at 21:47
  • @TonyMkenu you are right about the analytics part, but getting current installation should be local. Even the Parse's own documentation clearly says it: "Gets the currently-running installation from disk and returns an instance of it. If this installation is not stored on disk, returns a `PFInstallation` with and fields set to those of the current installation." – Can Poyrazoğlu Dec 14 '14 at 21:58
  • Did you post this on the [Google Group](https://groups.google.com/forum/#!forum/parse-developers)? – race_carr Dec 14 '14 at 22:14
  • @CanPoyrazoğlu you should do that. The Parse guys monitor that discussion forum (moreso than here at SO.) – race_carr Dec 15 '14 at 18:05
  • I see the same issue – pds Dec 16 '14 at 00:26
  • @PaulSchmitt could you post this as an answer so I can accept it for future visitors, please? – Can Poyrazoğlu Dec 21 '14 at 20:19

1 Answers1

7

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.

pds
  • 322
  • 1
  • 9
  • I experience the same thing but without the PFInstallation line. Only the enableLocalDatastore line was causing the warning. Also using dispatch_async does not work, because if I do this in AppDelegate and I want to call [PFUser currentUser] the app will crash if I don't have enableLocalDatastore before [PFUser currentUser]. I can't put both in dispatch_async because I want to show a different view controller in AppDelegate depending on if PFUser currentUser exists or not, and sort of assuming that I can't really do that in dispatch_async in AppDelegate. – Fraggle Dec 22 '14 at 16:21
  • @Fraggie -- see the modified answer using dispatch_async(dispatch_get_main_queue(), ^(void){}); – pds Dec 22 '14 at 16:48