2013-11-28 52 views
1

我已經在info.plist文件中設置了FacebookAppID,FacebookDisplayName,URLSchemes。在我最初的viewController中,我有以下功能。Facebook ios sdk 3.10 openActiveSessionWithReadPermissions不使用網絡登錄回調

但是,在調用openActiveSessionWithReadPermissions之後,它不會被稱爲NSLog等等。

- (IBAction)facebookLoginButtonClickHandler:(id)sender 
{ 

    NSArray *permissions = [[NSArray alloc] initWithObjects: 
          @"email", @"read_stream", @"user_about_me", @"user_birthday", 
          nil]; 
    FBSession *session = [[FBSession alloc] initWithPermissions:permissions]; 
    [FBSession setActiveSession:session]; 

    [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 

     NSLog(@"session = %@", session); 
     NSLog(@"error = %@", error); 

     if (status == FBSessionStateClosedLoginFailed || status == FBSessionStateCreatedOpening) { 
      [[FBSession activeSession] closeAndClearTokenInformation]; 
      [FBSession setActiveSession:nil]; 
     } else if (!session.isOpen) { 
      [[FBSession activeSession] closeAndClearTokenInformation]; 
      [FBSession setActiveSession:nil]; 
     } else { 
      NSLog(@"accessToken = %@", session); 
     } 
    }]; 
} 

回答

6

您需要添加到您的AppDelegate:

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    [FBAppEvents activateApp]; 
    [FBAppCall handleDidBecomeActive]; 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
    [FBSession.activeSession close]; 
} 

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 
{ 
    return [FBSession.activeSession handleOpenURL:url]; 
} 
+0

的感謝!我可以做到這一點。 – naohide

+0

在SDK 4中如何工作? – jose920405

相關問題