IOS / Swift: PFFacebookUtils.logInWithPermissions returns user nil and error

In my application, I log in using the Parse class PFFacebookUtil. If the user exists on the phone (i.e., logged into FB in Settings> Facebook), then everything works as expected.

But if they are not logged in through the settings , the user goes to the web view to enter the system. After the user enters his credentials, the return block should receive the user or error, but in this case the user and the error are zero.

    let permissionsArray = ["user_about_me", "email"];
    PFFacebookUtils.logInWithPermissions(permissionsArray, block: {
        (user: PFUser!, error: NSError!) -> Void in
        if user != nil {
              //successful login
        } else if error != nil{
              //unsuccessful login 
        } else {
              //this is what I get
        }
    }

We are currently running Parse 1.4.2

+4
3

, FBAppCall.handleOpenURL() AppDelegate:

application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) 

-. FBAppCall.handleOpenURL(), Parse , . , " - , ".

FBAppCall.handleOpenURL, . , . sourceApplication, , "com.facebook.Facebook". , FBAppCall.handleOpenURL(). , , "com.apple.mobilesafari". sourceApplication - , ( - url.host), .

:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) {
    if (url.host == DEEP_LINKING_HOST) {
       //Deep linking code here...
    } else if sourceApplication == "com.apple.mobilesafari" {
       return FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication, withSession: PFFacebookUtils.session())
   }
}

, FBAppCall.handleOpenURL(). , .

+2

. null NSError PFUser, .

, Facebook, parse, objective-c, , ... PFUser NSError log PFUser NSError. Parse.com Facebook. , Objective-C.

[PFFacebookUtils logInWithPermissions:@[@"public_profile", @"email"] block:^(PFUser *user, NSError *error) {
    if (error) {
        [CBUtility facebookErrorHandler:error];
        return;
    } else {
        if (![CBUtility userHasValidFacebookData:user]) {
            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (error) {
                    [CBUtility facebookErrorHandler:error];
                    return;
                }

                NSDictionary *user = (NSDictionary *)result;

                if (!user[@"email"]) {
                    [[[UIAlertView alloc] initWithTitle:@"Facebook Login/Register Error"
                                                message:[NSString stringWithFormat:@"There is no email associated with the current facebook account. The Registration could not proceed! Either login to your facebook account and create one or create a new crossbook account in the Register view."]
                                               delegate:nil
                                      cancelButtonTitle:nil
                                      otherButtonTitles:@"Dismiss", nil] show];
                    [[PFUser currentUser] delete];
                    return;
                }

                [PFUser currentUser][kCBUserFirstNameKey] = user[@"first_name"];
                [PFUser currentUser][kCBUserLastNameKey] = user[@"last_name"];
                [PFUser currentUser][kCBUserDisplayNameKey] = user[@"name"];
                [[PFUser currentUser] setEmail:user[@"email"]];
                [PFUser currentUser][kCBUserGenderKey] = [user[@"gender"] capitalizedString];
                [PFUser currentUser][kCBUserFacebookIDKey] = user[@"id"];

                if ([user[@"birthday"] length] != 0) {
                    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                    [dateFormatter setDateFormat:@"MM/dd/yyyy"];
                    NSDate *date = [dateFormatter dateFromString:user[@"birthday"]];
                    NSDateFormatter *stringFormatter = [[NSDateFormatter alloc] init];
                    [stringFormatter setDateFormat:@"MMM dd, yyyy"];
                    [PFUser currentUser][kCBUserBirthdateKey] = [stringFormatter stringFromDate:date];
                }

                [[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {


                    if ([error code] == 203) {
                        [[[UIAlertView alloc] initWithTitle:@"Facebook Login/Register Error"
                                                    message:[NSString stringWithFormat:@"Apparently, the email address %@ has already been taken. Login with the username and password that is associated with the email address %@ and link accounts to allow facebook login by going to settings and link facebook account. If you forgot the password for the account, press 'Forgot Password' and type in the email address.", user[@"email"], user[@"email"]]
                                                   delegate:nil
                                          cancelButtonTitle:nil
                                          otherButtonTitles:@"Dismiss", nil] show];
                        [[PFUser currentUser] delete];
                        return;
                    }

                    if (error) {

                        [[[UIAlertView alloc] initWithTitle:@"Error"
                                                    message:[error localizedDescription]
                                                   delegate:nil
                                          cancelButtonTitle:nil
                                          otherButtonTitles:@"Dismiss", nil] show];
                        [PFUser logOut];
                        return;
                    }

                    [[NSNotificationCenter defaultCenter] postNotificationName:CBLoginRegisterControllerUserDidFinishLoginNotification object:nil];
                    [self dismissViewControllerAnimated:YES completion:nil];
                    [(AppDelegate *)[[UIApplication sharedApplication] delegate] downloadFacebookPhoto];
                    return;
                }];
            }];
            return;
        }

        [[NSNotificationCenter defaultCenter] postNotificationName:CBLoginRegisterControllerUserDidFinishLoginNotification object:nil];
        [self dismissViewControllerAnimated:YES completion:nil];
        [(AppDelegate *)[[UIApplication sharedApplication] delegate] downloadFacebookPhoto];
        return;
    }
}];
0

4.10.1 SDK Facebook. FBAppCall. FBSDKApplicationDelegate .

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL canOpen = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];

    return canOpen;
}
0

All Articles