简体   繁体   English

FBSession,检查是否已登录?

[英]FBSession, checking if logged in?

I have implemented the facebook login into my app however right now I've been playing around with the login/logout states and what a modal view to pop only if the user is logged out...anyways this is what I have and its not working? 我已经在我的应用程序中实现了Facebook登录,但是现在我一直在尝试登录/退出状态以及仅当用户注销时才会弹出的模式视图...无论如何,这就是我所拥有的,而没有工作吗

 if (FBSessionStateClosed) {
     [self performSegueWithIdentifier:@"TestModal" sender:nil];
 }

Thanks for any help! 谢谢你的帮助!

If I get u correctly, your session should be still Open. 如果我正确理解了您,则您的会话应该仍处于打开状态。 Double check did you perform this line when user logout? 仔细检查用户注销时是否执行了此行?

[FBSession.activeSession closeAndClearTokenInformation];

Hope this help 希望这个帮助

Use Following method may be help you : 使用以下方法可能会帮助您:

-(void)openFacebookAuthentication
{
    NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission, nil];

    FBSession *session = [[FBSession alloc] initWithPermissions:permission];

    [FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission] ];

    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

        switch (status) {
            case FBSessionStateOpen:
                [self getMyData];
                break;
            case FBSessionStateClosedLoginFailed: {
                // prefer to keep decls near to their use
                // unpack the error code and reason in order to compute cancel bool
                NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
                NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
                BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);


                if(error.code == 2 && ![errorReason isEqualToString:kFBSdkUserLoginFail]) {
                    UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle
                                                                           message:kFBAuthenticationErrorMessage
                                                                           delegate:nil
                                                                           cancelButtonTitle:kOk
                                                                           otherButtonTitles:nil];
                    [errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
                    errorMessage = nil;
                    }
                }
                break;
                // presently extension, log-out and invalidation are being implemented in the Facebook class
            default:
                break; // so we do nothing in response to those state transitions
        }
    }];
    permission = nil;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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