Facebook iOS SDK 请求权限 publish_actions,但用户需要再次输入密码

Facebook iOS SDK request permission publish_actions, but user need to input password again

Facebook iOS我的项目用的是SDK 3.8,现在升级到3.22了。

在请求"publish_actions"权限时发生了一件奇怪的事情,即用户需要重新输入她的帐号和密码。而在以前的版本中 "login again" 部分将被跳过。我想知道 Facebook SDK 中的逻辑是否发生变化,或者我必须更改会话处理过程。关于这个问题有什么想法吗?

我以前申请"publish_actions"权限的方式是:

 [activeSession openWithBehavior: FBSessionLoginBehaviorForcingWebView
        completionHandler:^(FBSession *session,
                            FBSessionState state, NSError *error) {
    [session reauthorizeWithPermissions:@[@"publish_actions"]
                                                                        isRead:NO
                                                                      behavior:FBSessionLoginBehaviorForcingWebView
                                                               defaultAudience:FBSessionDefaultAudienceFriends
                                                             completionHandler:^(FBSession *session, NSError *error) {
 }

我也试过了

[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                          defaultAudience:FBSessionDefaultAudienceFriends
                                    completionHandler:^(FBSession *session, NSError *error) {
                                        __block NSString *alertText;
                                        __block NSString *alertTitle;
                                        _reauthorizeInProgress = YES;
                                        if (!error) {
                                            if ([FBSession.activeSession.permissions
                                                 indexOfObject:@"publish_actions"] == NSNotFound){
                                                // Permission not granted, tell the user we will not publish
                                                alertTitle = @"Permission not granted";
                                                alertText = @"Your action will not be published to Facebook.";
                                                [[[UIAlertView alloc] initWithTitle:alertTitle
                                                                            message:alertText
                                                                           delegate:self
                                                                  cancelButtonTitle:@"OK!"
                                                                  otherButtonTitles:nil] show];
                                            } else {
                                                // Permission granted, publish the OG story

                                            }

                                        } else {
                                            // There was an error, handle it
                                            // See https://developers.facebook.com/docs/ios/errors/
                                        }
                                    }];

此行为是 Facebook 的默认设置。文档 https://developers.facebook.com/docs/facebook-login/ios/v2.2 说:

The Disadvantage of WebView is:

People have to fill in their login credentials every time they go through the login flow.

在 FBSession.m 文件中,我更改了方法

中的代码
- (void)retryableAuthorizeWithPermissions:(NSArray *)permissions
                      defaultAudience:(FBSessionDefaultAudience)defaultAudience
                       integratedAuth:(BOOL)tryIntegratedAuth
                            FBAppAuth:(BOOL)tryFBAppAuth
                           safariAuth:(BOOL)trySafariAuth
                             fallback:(BOOL)tryFallback
                        isReauthorize:(BOOL)isReauthorize
                  canFetchAppSettings:(BOOL)canFetchAppSettings

并且在请求其他权限时不要删除cookie,替换

   // To avoid surprises, delete any cookies we currently have.
    [FBUtility deleteFacebookCookies];

    // To avoid surprises, delete any cookies we currently have.
if(!isReauthorize){
    [FBUtility deleteFacebookCookies];
}

我同意修改SDK源码不是一个好主意,但我应该在用户体验的一致性和代码风格之间做一些平衡。 ;(