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];
}
}];
}
}