FacebookSDK提供两次登录界面 [英] FacebookSDK presents login UI twice

查看:142
本文介绍了FacebookSDK提供两次登录界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iOS 6与FacebookSDK将读取和发布权限的请求分成两个单独的呼叫。我不知道为什么这样做有什么好处,但是似乎需要首次向用户提供两次Facebook界面。

Using iOS 6 with the FacebookSDK splits the requests for read and publish permissions into two separate calls. I'm not sure why there's any benefit to this, but it seems to require presenting the user with the Facebook UI twice the first time thru.

在我的应用程序中,我在用户选择使用Facebook之前,不要求任何内容,在这种情况下,他们首先被提供给用户界面以获取读取权限,然后再次获取发布权限。控制从我的应用程序切换到Facebook(阅读)回到我的应用程序,然后立即返回到Facebook(发布),然后回到我的应用程序。

In my app, I don't request anything from Facebook until a user chooses to use Facebook, in which case they are first presented with the UI to get read permissions, then again to get publish permissions. Control switches from my app to facebook (for read) back to my app and then immediately back to facebook (for publish) then back to my app.

这是一个可怕的用户体验特别是因为Facebook屏幕与Okay看起来和用户一样。 (为什么要两次按Ok?)

This is an awful user experience, especially since the facebook screen with the "Okay" looks the same to the user. (Why am I pressing Okay twice?)

简而言之,我的代码是:

My code, in a nutshell is:

Check for a valid FBSession.activeSession
if not open call FBSession openActiveSessionWithReadPermissions
if successful call FBSession.activeSession reauthorizeWithPublishPermissions
then publish post

代码有效,但用户体验不好。我错过了什么吗?

The code works, but the user experience is lousy. Am I missing something?

推荐答案

我的理解是,iOS 6需要双重登录他们的 ACAccountStore 支持,所以Facebook 登录教程意味着你应该这样做所有情况。切换应用程序两次是一个糟糕的用户体验,我想我已经想出了一个工作。

My understanding is that iOS 6 is requiring the double login for their ACAccountStore support, so the Facebook login tutorial implies that you should do this for all cases. Switching the app twice is a bad user experience and I think I have come up with a work around.

首先,对于较旧的iOS(例如iOS 5.0),您只需使用 openActiveSessionWithPublishPermissions:并进行阅读和发布权限一下子。其次,如果用户从未从设备设置登录到Facebook,则可以使用相同的调用。因此,以下代码似乎如下所示:

Firstly, for older iOS's (e.g iOS 5.0) can you just use openActiveSessionWithPublishPermissions: and do the read and publish permissions in one swoop. Secondly, this same call works if the user has never logged into Facebook from the Device Settings. Therefore, the following code seems to work like this:


  • 如果用户从设备设置登录了Facebook:
    的一个对话框阅读和一个对话框发布。

  • 否则如果用户安装了Facebook应用程序:
    切换到FB应用程序一次,并连续获得2个提示。

  • 否则:将
    转换为Safari一次,并连续获得2个提示

我在iOS6和iOS5设备上测试了这个代码,使用Facebook SDK 3.2.1

I tested this code on an iOS6 and iOS5 device, using Facebook SDK 3.2.1

- (BOOL)hasFacebookInDeviceSettings
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"];
    BOOL hasFacebookBuiltinAccount = (accountTypeFB != nil);
    return hasFacebookBuiltinAccount;
}

- (BOOL)hasLoggedInToFacebookInDeviceSettings
{
    if (![self hasFacebookInDeviceSettings]) {
        return NO;
    }
    BOOL result = [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
    return result;
}

- (void)openFacebookSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
    if (![self hasLoggedInToFacebookInDeviceSettings]) {
        // Simpler if we don't have the built in account
        [FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"]
                                           defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self facebookSessionStateChanged:session
                                                                         state:state
                                                                         error:error];
                                         }];
    }
    else if (!FBSession.activeSession.isOpen) {
        __block BOOL recursion = NO;
        [FBSession openActiveSessionWithReadPermissions:nil
                                           allowLoginUI:allowLoginUI
                                      completionHandler:^(FBSession *session,
                                                          FBSessionState state,
                                                          NSError *error) {
                                          if (recursion) {
                                              return;
                                          }
                                          recursion = YES;
                                          if (error || !FBSession.activeSession.isOpen) {
                                              [self facebookSessionStateChanged:session
                                                                          state:state
                                                                          error:error];
                                          }
                                          else {
                                              assert(FBSession.activeSession.isOpen);
                                              if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
                                                  [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
                                                                                        defaultAudience:FBSessionDefaultAudienceFriends
                                                                                      completionHandler:^(FBSession *session,
                                                                                                          NSError *error) {
                                                                                          [self facebookSessionStateChanged:session
                                                                                                                      state:FBSession.activeSession.state
                                                                                                                      error:error];
                                                                                      }];
                                              }
                                          }
                                      }];
    }
}

haveFacebookInDeviceSettings 告诉你这个设备是否甚至支持Facebook的设置(即这是iOS6 +)。

hasFacebookInDeviceSettings tells you if this device even supports Facebook from the settings (i.e. this is iOS6+).

hasLoggedInToFacebookInDeviceSettings 告诉您用户是否已从iOS6的Facebook设备设置登录到Facebook。

hasLoggedInToFacebookInDeviceSettings tells you if the user has signed into to Facebook from the iOS6 Facebook device settings.

您需要创建自己的 facebookSessionStateChanged:和其他代码,如登录教程

You'll need to create your own facebookSessionStateChanged: and other code, as described in the login tutorial

这篇关于FacebookSDK提供两次登录界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆