15

我一直在尝试使用 Facebook 开发 iOS 应用程序,我是新手。所以我一直在努力

使用 Facebook 登录,遵循 Facebook 上的教程并尝试实现它。

但是我遇到过,[FBSession sessionOpenWithPermissions]没找到。当我运行

应用程序,它将强制关闭并说出该错误。构建项目时,它会显示警告

sessionOpenWithPermission找不到的黄色感叹号FBSession

教程过时了?如果是,那么新的 Facebook SDK 的新代码是什么?

会话OpenWithPermission ?

4

7 回答 7

2

Maybe this code helps you, put it in your AppDelegate.m class

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen: {
            self.loggedinVCController = [[LoggedinVC alloc] initWithNibName:@"LoggedinVC" bundle:nil];
            self.navController = [[UINavigationController alloc]initWithRootViewController:self.loggedinVCController];
            self.window.rootViewControlle`enter code here`r = self.navController;

        }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // be looking at the root view.
            [self.navController popToRootViewControllerAnimated:NO];

            [FBSession.activeSession closeAndClearTokenInformation];

            self.viewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
            self.window.rootViewController = self.viewController;

            break;
        default:
            break;
    }

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [FBSession.activeSession handleOpenURL:url];
}
- (void)openSession
{
    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}
于 2013-09-26T07:37:14.647 回答
2

试试这个代码

 account = [[ACAccountStore alloc] init];
    accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    arrayOfAccounts = [account accountsWithAccountType:accountType]; 


    appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
    chk=appDelegate.chk_login;

    if (!appDelegate.session.isOpen) {
        // create a fresh session object
        appDelegate.session = [[FBSession alloc] init];
        if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
            // even though we had a cached token, we need to login to make the session usable
            [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {
                // we recurse here, in order to update buttons and labels

            }];
        }
    }
于 2013-09-19T12:03:51.723 回答
1

FBSession的 Facebook iOS SDK 3.0 登录教程问题可能重复

//REPLACE
[FBSession sessionOpenWithPermissions:nil
                    completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) {
                        [self sessionStateChanged:session state:state error:error];
                    }];

//WITH
[FBSession openActiveSessionWithPermissions:nil
                               allowLoginUI:YES
                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                              [self sessionStateChanged:session state:state error:error];
                          }];
于 2013-04-18T08:36:47.577 回答
1

它打开 facebook seesion 并可选择显示登录 ux

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"email",
                            @"user_likes",
                            nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];}
于 2013-07-30T09:44:48.270 回答
0

只需将@Stas Zhukovskiy 的答案复制到答案框的评论中即可:

文档教程和示例不匹配。你应该使用 - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI; 反而。——斯塔斯茹科夫斯基

于 2013-04-09T01:51:51.430 回答
0

App Delegate 中缺少某些行代码。只需检查那个。之后,您将在调用 Facebook 方法时检查打开会话和关闭会话。

于 2013-09-10T11:34:36.480 回答
0

你也可以使用 Sharekit 它非常容易实现并且还支持其他社交网络。 共享工具包

分享套件教程

于 2013-07-08T09:49:29.857 回答