简体   繁体   中英

Problems to login on facebook using social framework on ios

I'm using this code to make a facebook login , and it was working very well in 6.7 version of facebook app.

when the version of the facebook app is the 6.8, the login doesn't work! Someone can imagine what is going on??

the code i'm using is...

ACAccountType *facebookTypeAccount = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    [self.accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                               options:@{ACFacebookAppIdKey:facebookAppNumber, ACFacebookPermissionsKey: @[@"email"]}
                                        completion:^(BOOL granted, NSError *error)
     { 

         if(granted)
         {
             NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
             //NSLog(@"accounts %@",accounts);
             self.facebookAccount = [accounts lastObject];

             checkFbStatus = statusWaiting;
             [self me];
             userFbEmail = [jay valueForKey:INFO_FB_EMAIL];
             facebookId = [jay valueForKey:INFO_FB_ID];

         }
         else
         {

             NSLog(@"one");
             //aqui você 
             if([error code]== ACErrorAccountNotFound)
             {

                 //[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
                 SLComposeViewController * fb = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
                 fb.view.hidden = YES;
                 [self presentViewController:fb animated:NO completion:nil];
                 checkFbStatus = statusFailed;

                 //Adicione sua conta de facebook nas configurações.

             }
             else
             {

                 //Erro desconhecido ou então o usuário não deu permissão.

                 checkFbStatus = statusFailed;


             }
         }
     } ];

I faced same problem :

had to make

@property (strong, nonatomic) FBSession *session;

in AppDelegate

in

(void)applicationDidBecomeActive:(UIApplication *)application { [FBAppEvents activateApp]; [FBAppCall handleDidBecomeActiveWithSession:self.session]; }
in

(void)applicationWillTerminate:(UIApplication *)application { [self.session close]; }
in

(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:self.session]; }
in your settings class

if (appDelegate.session.isOpen) {

        [FBSession setActiveSession:appDelegate.session];
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary *user, NSError *error) { [self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error]; }];

    }
    else
    {
        [appDelegate.session closeAndClearTokenInformation];
        NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
        appDelegate.session = [[FBSession alloc] initWithPermissions:permissions];
        [FBSession setActiveSession:appDelegate.session];

        [appDelegate.session openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView)
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { [self sessionStateChangedWithFBSession:session andFBSessionState:status andNSError:error]; }];

    }
(void)sessionStateChangedWithFBSession:(FBSession*)session andFBSessionState:(FBSessionState)status andNSError:(NSError*) error { switch (status) { case FBSessionStateOpen: { [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {

         [self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error];
     }]; }
    break;
case FBSessionStateClosed:

    break;
case FBSessionStateClosedLoginFailed:

    break;
default:
    break;
} }

in your in registerationWithFBRequestConnection : methods you can get all information for login.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM