首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ios6 facebook集成登录始终FBSessionStateClosedLoginFailed从不打开

ios6 facebook集成登录始终FBSessionStateClosedLoginFailed从不打开
EN

Stack Overflow用户
提问于 2012-09-30 20:02:02
回答 6查看 15.7K关注 0票数 16

这个问题与Facebook SDK for iOS , on iOS 4.0 device非常相似,但由于我不能在那里发表评论,所以我打开了一个新问题。我认为问题是不一样的:

当我试图将我的应用程序的facebook集成更新到facebook 3.1时,我没有得到facebook会话来打开sessionStateChanged回调总是以FBSessionStateClosedLoginFailed结束。在我的设置中,我的应用程序委托中有一个回调

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    // attempt to extract a token from the url
    //    return [self.session handleOpenURL:url]; 
    return [FBSession.activeSession handleOpenURL:url];
}

但它从未被调用过!它不应该被调用吗?我按照facebook的文档打电话给

代码语言:javascript
复制
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
    return [FBSession openActiveSessionWithPublishPermissions:permissions
                                              defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];
}

我也试过了

与facebook教程示例中的权限相同,使用nil对权限执行openActiveSessionWithReadPermissions,并打算稍后重新授权publish_actions权限。同样的结果:再次使用FBSessionStateClosedLoginFailed。

我甚至试着给你打电话

代码语言:javascript
复制
ACAccountStore *accountStore;
    ACAccountType *accountTypeFB;
    if ((accountStore = [[ACAccountStore alloc] init]) &&
        (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){

        NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
        id account;
        if (fbAccounts && [fbAccounts count] > 0 &&
            (account = [fbAccounts objectAtIndex:0])){

            [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
                //we don't actually need to inspect renewResult or error.
                if (error){

                }
            }];
        }
    }

在尝试打开会话之前,我从未在我的ios6设备(IPhone4s)上打开它。在应用程序中,我被要求获得权限,但随后什么都没有发生,因为会话始终具有状态FBSessionStateClosedLoginFailed!我对会话状态的回调是

代码语言:javascript
复制
- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if (!error) {
                // We have a valid session
                NSLog(@"User session found");
            }
            break;
        case FBSessionStateClosed:
            NSLog(@"FBSessionStateClosed");
        case FBSessionStateClosedLoginFailed:
            NSLog(@"FBSessionStateClosedLoginFailed");
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }

    [[NSNotificationCenter defaultCenter]
     postNotificationName:FBSessionStateChangedNotification
     object:session];

    if (error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"facebook Hinweis"
                                                        message:@"facebook Login nicht möglich, bitte versuchen Sie es erneut."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        NSLog(@"Facebook session error: %@", error.localizedDescription);
    }
}

使用iOS5上的facebook 3.0,我从来没有遇到过问题,所以我的facebook应用程序设置正确。我真的很感谢任何人的帮助,wchich使我能够打开facebook会话,我没有想到在facebook 3.1中遇到这些问题,文档在这一点上对我没有帮助,谢谢

EN

回答 6

Stack Overflow用户

发布于 2012-12-31 06:43:08

我也遇到了同样的问题,这是因为我忘了实现

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [FBSession.activeSession handleOpenURL:url];
}

在我的AppDelegate

票数 40
EN

Stack Overflow用户

发布于 2013-03-20 03:19:29

虽然JohnG的答案是正确的,但这个特定的委托方法现在已经是deprecated了。使用is this的正确委托方法

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [FBSession.activeSession handleOpenURL:url];
}

把它放到我的应用程序代理中就解决了这个问题。如果没有这一点,Facebook6.0本机登录可以正常工作,但iOS应用程序登录将失败。

票数 19
EN

Stack Overflow用户

发布于 2013-08-23 17:05:37

我也有同样的问题。如果用户没有在系统首选项中配置Facebook帐户,则会出现Facebook登录对话框,一切工作正常。但是,如果用户在设备中配置了帐户,我总是会遇到FBSessionStateClosedLoginFailed错误。

它与handleOpenURL:url没有任何关系,因为在iOS 6或更高版本的“本地登录流”中,没有快速的应用程序切换。因此,您的应用程序永远不会转到后台,也不需要URL重定向。

配置Facebook应用程序解决了这个问题。您需要启用“本地iOS登录”部分,并输入您的应用程序的捆绑包ID。如果您的应用程序尚未在Apple Store中,恐怕您需要将沙盒模式设置为打开。一旦你的应用在苹果商店发布,我认为你需要关闭沙盒模式,并在Facebook配置中设置苹果商店ID。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12661104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档