-2

如果我在 Safari 中没有 Facebook 会话或设备上的 Facebook 本机应用程序没有 Facebook 会话,我正在使用 FBLoginView,这个 FBLoginView 没有采用 Facebook 会话表单设置

图片

4

1 回答 1

0

使用对我来说工作正常:

 -(void)LinkeToFaceBook:(NSString *)stringRequest{

        if ([HostSite checkServerConnected :kNetworkSuccess withFailureNote:kNetworkFailure])
        {
            if (!FBSession.activeSession.isOpen) {
                [FBSession.activeSession closeAndClearTokenInformation];
                FBSession.activeSession=nil;
                [self openFacebookAuthentication];
            }
        } else {
            [self networkAlertShow];

        }

    }

    -(void)openFacebookAuthentication
    {
        NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission,kFBUserPublicPermission,kFBUserLikePermission, 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 likeFaceBook];
                    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) {
                        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;
    }
于 2013-08-12T13:24:10.860 回答