我在我的应用程序中集成了 facebook sdk 3.2.1,当我尝试登录时出现此错误
The Operation couldn't be completed.(com.facebook.sdk error 2.0) error. iOS 6
这主要发生在用户的手机预装了 Facebook 应用程序时,当他尝试通过我的应用程序登录 facebook 时,我收到错误消息。如果我从 iPhone 中的 facebook 应用程序中注销帐户,那么它工作正常。
我该如何克服这个问题,请帮助我克服这个问题。
作为参考,我使用的代码是
- (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];
}
}];
}
}