2012-08-09 97 views
15

我一直在嘗試使用Facebook開發iOS應用程序,而我是新手。所以我一直試圖讓新的Facebook SDK FBSession sessionOpenWithPermissions

與Facebook登錄,遵循Facebook上的教程,並嘗試實施它。

但我遇到過,找不到[FBSession sessionOpenWithPermissions]。當我運行

應用程序時,它將強制關閉並說出錯。當生成項目,它將會顯示警告

黃色感嘆號是sessionOpenWithPermissionFBSession

教程過時的發現?如果是,那麼新的Facebook SDK的新代碼是什麼?

sessionOpenWithPermission?

+3

我認爲這是有效─我有Facebook的例子同樣的問題。 – 2012-08-09 18:29:49

+1

這顯然是一個文檔不匹配問題。我建議查看SDK附帶的「最好的」示例應用程序以獲取最新的文檔。 – Bringo 2012-08-10 23:42:34

+4

在文檔教程和示例中存在不匹配。你應該使用' - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;'而不是。 – 2012-08-14 21:07:20

回答

0

只複製在評論回答框@Stas茹科夫斯基答案:

沒有在文檔教程和樣品不匹配。你應該使用 - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;代替。 - Stas Zhukovskiy

1

Facebook iOS SDK 3.0 Login Tutorial Issue with FBSession

//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]; 
          }]; 
0

可能的複製,你也可以使用Sharekit 這是很容易實現的,同時還支持其他社交網絡。 sharekit

Share kit tutorial

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]; 
             }];} 
+0

viruss mca。您在我的代碼中做了什麼修改 – ArunMak 2013-07-30 10:03:54

0

線的一些代碼在應用Delegate.Just查缺的是one.after,美將開查Facebook的調用方法時間和閉會期間。

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 

      }]; 
     } 
    } 
+0

由於'FBSession'具有'activeSession'靜態公共變量,因此您不必將會話保存在應用程序委託中。 – Zorayr 2014-04-29 03:44:55

2

也許這個代碼可以幫助你,把你的AppDelegate.m

- (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]; 
    }]; 
} 
相關問題