1

I have integrated facebook sdk 3.2.1 in my app, When i am trying to login i am getting this error

The Operation couldn't be completed.(com.facebook.sdk error 2.0) error. iOS 6

This is mainly occurring when User's phone has preinstalled Facebook App, and when he tries to login into facebook through my app then i am getting error. If I am logging out the account from the facebook app in iPhone, then it is working fine.

How can I overcome this issue,Kindly help me out to overcome this.

For reference, The code I am using is

- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if (!error) {
                // We have a valid session
                NSLog(@"User session found");
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FBFirstTime"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                [self populateUserDetails];

                if([[NSUserDefaults standardUserDefaults] boolForKey:@"FBFirstTime"])
                {
                  }
                else
                {
                    NSLog(@"1st Time");
                }
            }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"
                                                            message:@"Facebook login failed. Please check your Facebook settings on your phone."
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        default:
            break;
    }

    [[NSNotificationCenter defaultCenter] postNotificationName:FBSessionStateChangedNotification object:session];

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}

//

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    //    NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", @"user_likes", nil];
    NSArray* permissions = [[NSArray alloc] initWithObjects:@"user_birthday",
                            @"user_about_me",
                            @"user_checkins",
                            @"user_hometown",
                            @"user_activities",
                            @"user_events",
                            nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];
}

//

- (void)populateUserDetails
{
    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
            if (!error) {
                NSThread *contactsObjectsThread = [[NSThread alloc]initWithTarget:self selector:@selector(createUserContactsObjects) object:nil];
                [contactsObjectsThread start];


                [activityView stopAnimating];
            }
        }];
    }
}
iOSDev
  • 412
  • 10
  • 30

4 Answers4

0

Check Single sign-on in off developer.facebook.com...

Nik's
  • 690
  • 1
  • 10
  • 27
0

I had a similar problem, when you change your password or you change the fb permission of an app the fb token should change and you need to update your password or accept again the permission manually...

in the past there was a bug on the fb sdk that should be fixed, so my suggestion is update to the latest version and check for 'Sub Error' and check if the problem is the password, permission etc... and inform the user about the related action to restore the login

Manu
  • 788
  • 5
  • 10
  • Okay Manu, I will give a try. – iOSDev Aug 12 '13 at 14:21
  • I have taken the 3.6 SDK which the latest and ran in my phone, still I am facing the same problem – iOSDev Aug 12 '13 at 15:58
  • have you check the SubError? you should be able to see more information about the error into the subError object – Manu Aug 12 '13 at 15:59
  • every NSError in the facebook-sdk should implement the category interface of FBError, if you see there are more information about the meaning of the error – Manu Aug 12 '13 at 16:04
  • No Manu, i am not able to find it out that section. – iOSDev Aug 12 '13 at 23:44
  • put a break point in your sessionStateChanged and print the dictionary [error userInfo] you should see the additional information about the error – Manu Aug 13 '13 at 17:21
0

I was able to Fix the Issue finally, https://stackoverflow.com/a/13321162/1079929 by following this Answer
In Our developers.facebook, in our app, we need to add our BundleID in iOS Native App, and Facebook Login Enabled... that fixed the issue

Community
  • 1
  • 1
iOSDev
  • 412
  • 10
  • 30
0

Make sure you are using same bundle identifier in your app that you have given at developer.facebook.com when creating the app.

Sourabh Bhardwaj
  • 2,524
  • 1
  • 17
  • 19