FBSession Completion Handler无法正常工作并打开url未调用?

时间:2014-11-18 13:15:10

标签: ios objective-c iphone facebook xcode6

appdelegate.m

  if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
        // Yes, so just open the session (this won't display any UX).
        NSLog(@"token loaded");
        [self openSession];
    } else {
        // No, display the login page.
        //[self showLoginView];
        NSLog(@"token not loaded");

    }

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    // We need to properly handle activation of the application with regards to Facebook Login
    // (e.g., returning from iOS 6.0 Login Dialog or from fast app switching).
    [FBSession.activeSession handleDidBecomeActive];
}

pragma mark -

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen: {
            NSLog(@"session state open");
        }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:

            [FBSession.activeSession closeAndClearTokenInformation];
            NSLog(@"session state closed");

            break;
        default:
            break;
    }

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}

- (void)openSession
{


    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile, email, user_friends"] allowLoginUI:YES completionHandler:^(FBSession *session,
       FBSessionState state, NSError *error) {
        NSLog(@"It is never called");

         [self sessionStateChanged:session state:state error:error];
     }];
}

- (void)obatinUserInfo {


}

pragma mark -

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    NSLog(@"it is never called");
    return [FBSession.activeSession handleOpenURL:url];
}

查看controller.m

===========

按钮操作

- (IBAction)performLogin:(id)sender {

    AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate openSession];
}

这是我的代码,当调用Facebook登录进入opensession,但未在完成处理程序和打开网址内调用。 我提到的许多链接但不起作用。 相同的代码工作的单个项目,但集成到我的项目中意味着无法工作。

请帮助我

提前致谢 S.Arul

0 个答案:

没有答案