Parse loginWithUsernameInBackground block callback

2020-08-02 06:42发布

问题:

So I have a parse app in the appstore already. I'm about to submit an update for the app using the latest Parse SDK 1.7.4 and I noticed the manual parse login IS NOT WORKING!

I hope this is due to my code and not a parse issue because that's a major f**k up if you ask me...

Anyway, here is the code, any help is appreciated.

[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {        
if (!error) {
   //do stuff with user
} else { 
   //error handling here     
}

I of course did some search on the internet to find an answer and most people are saying not to use the background functions because things need to run on the main thread. And I tried using the dispatch async and forced it to run on the main thread but still no callback from the login.

Here is the error msg I'm getting:

-[BFTask isFaulted]: unrecognized selector sent to instance  
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BFTask isFaulted]: unrecognized selector sent to instance

When I run the below code:

NSError *error;
PFUser *user = (PFUser *)[PFUser logInWithUsername:username password:password error:&error];
if (error) {
   //do error handling here
} else {
   //do stuff with user object here and go to logged in screen.
}

Also, I wanna note, I have this:

NSString *const BFTaskMultipleExceptionsException = @"BFMultipleExceptionsException";

in my AppDelegate just to be able to compile and run the app ever since I upgraded to Parse 1.7.4 SDK.

These are the errors I get if I take out this line from the AppDelegate:

  "_BFTaskMultipleExceptionsException", referenced from:
      ___53+[PFObject(Private) deleteAllAsync:withSessionToken:]_block_invoke226 in Parse(PFObject.o)
      ___65+[PFObject(Private) _deepSaveAsync:withCurrentUser:sessionToken:]_block_invoke319 in Parse(PFObject.o)

Here is a question that's similar to this in Parse blogs that's not really solved:

https://www.parse.com/questions/ios-sdk-loginwithusernameinbackgroundpasswordblock-does-not-execute-block-on-error-case

Thanks in advance for help.

回答1:

Unfortunately I cannot comment on your question (not enough reputation), but it seems you have an old FacebookSDK in your project. Xcode gives you a duplicate symbols error, which is caused by the fact that your (old) FacebookSDK has Bolts integrated. The moment you integrate it from the Parse SDK, you have it effectively two times in your project, resulting in the duplicate symbols error.

Please update your FacebookSDK to the last v3 version, available here. Then, use the latest ParseSDK, and include everything from Parse (also ParseUI, Bolts, etc, everything from their SDK folder EXCEPT the v4Facebook framework) into your project.

This should do the trick and your method:

[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {        
if (!error) {
   //do stuff with user
} else { 
   //error handling here     
}

should work.