Xcode facebook登录错误已关闭

Posted

技术标签:

【中文标题】Xcode facebook登录错误已关闭【英文标题】:Xcode facebook login error CLOSED 【发布时间】:2012-09-14 22:52:31 【问题描述】:

您好,我在http://developers.facebook.com/ 上阅读和阅读教程。

关于登录 Facebook 并从应用程序发布 Feed,我的问题是我根本无法登录 Facebook。

而且我无法让它工作。这很糟糕,很烦人,而且没有明确的教程/解释。

我试图从我的应用程序登录,当 safari 打开然后 URL 就像疯了一样 眨眼..

我没有收到错误,为什么?

有没有关于登录的 CLEAR 教程?

它在模拟器上工作得很好,但在设备上却不行。

我现在在 Xcode 4.5 测试版上,但它也不适用于 4.4。

我需要帮助!

[关闭]

编辑:我修好了!我太傻了……我在 7 天的时间里都在挣扎,只是为了登录 FB, 然后我改变了(设备上允许使用 Cookies),一切正常!

该死的设备只需要一些 cookie.. 哈哈

【问题讨论】:

【参考方案1】:

大约 2 周前我刚刚更新到最近的 FB sdk。这是我的做法:

//FB recommends to put these two in the app delegate in their sample apps but you can place them other places
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI 
    NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
    return [FBSession openActiveSessionWithPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session, FBSessionState state, NSError *error) 
                                         NSLog((@"session.state is %d",session.state));
                                         if(session.state==513)
                                             [AppPrefererences sharedAppPrefererences].faceBookLoggedIn=YES;
                                             NSLog((@"facebookLogin pref has been set to yes from inside appDelegate"));
                                         
                                         else
                                             [AppPrefererences sharedAppPrefererences].faceBookLoggedIn=NO;
                                         
                                     ];


- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation 
    // FBSample logic
    // We need to handle URLs by passing them to FBSession in order for SSO authentication
    // to work.
    return [FBSession.activeSession handleOpenURL:url];



    //Then whereever you want to initiate the log in (i use mine in a tableView)
      AppDelegate  *appDelegate =(AppDelegate*) [[UIApplication sharedApplication]delegate];

 if (![appDelegate openSessionWithAllowLoginUI:NO]) 
                    [appDelegate openSessionWithAllowLoginUI:YES];
                    facebookLoginLabel.text=@"Facebook Log Out";
                    [AppPrefererences sharedAppPrefererences].faceBookEnabled=YES;
                
                else
                    facebookLoginLabel.text=@"Facebook Log In";
                    [AppPrefererences sharedAppPrefererences].faceBookLoggedIn=NO;
                    [FBSession.activeSession closeAndClearTokenInformation];                    
                

然后,无论您想在哪里发布,都可以这样做:

  [FBRequestConnection startForPostStatusUpdate:@"any thing you want to post"
                                    completionHandler:^(FBRequestConnection *connection, id result, NSError *error)];

另外,别忘了设置 FBLoginViewDelegate

如果您有任何问题,请告诉我!希望对您有所帮助!

【讨论】:

什么是 AppPreferences ? 哦,我的错,这只是我用来实现 nsuserdefaults 的自定义类。忽略那部分

以上是关于Xcode facebook登录错误已关闭的主要内容,如果未能解决你的问题,请参考以下文章

Facebook 登录错误 - Xcode 8 GM

iOS Xcode 8.3 Facebook SDK 登录错误

Xcode 9 没有这样的模块“Facebook 登录”

facebook 错误:会话已关闭且未正常关闭(phonegap 构建/facebook 插件错误)

Xcode快速链接到Facebook页面[关闭]

Facebook 使用 Parse SDK 登录(iOS 9、Xcode 7.1、Swift 2.1)