【问题标题】:Facebook iOS SDK not calling completion handler when authorized appFacebook iOS SDK在授权应用程序时未调用完成处理程序
【发布时间】:2013-05-24 08:08:03
【问题描述】:

我调用 doFacebookLogin 我的应用切换到 facebook 以授权该应用,但在我允许该应用访问我的信息并切换回来之后。

什么都没有发生。控制台中没有“完成”。

如果我再次调用 doFacebookLogin,控制台会显示

complete
Session state closed

这是我的代码。

- (void)doFacebookLogin:(id)sender
{
[FBSession openActiveSessionWithReadPermissions:nil
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,FBSessionState state, NSError *error) {
     NSLog(@"complete");
     [self sessionStateChanged:session state:state error:error];
 }];
}

- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
NSLog(@"Session state changed");
switch (state) {
    case FBSessionStateOpen:
        NSLog(@"Session state open");
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
            if(error == nil) {
                NSLog(@"%@", [user debugDescription]);
            }
        }];
        break;

    case FBSessionStateClosed:
    case FBSessionStateClosedLoginFailed:
        NSLog(@"Session state closed");
        [FBSession.activeSession closeAndClearTokenInformation];
        break;

    default:
        break;
}

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

【问题讨论】:

    标签: ios objective-c facebook sdk


    【解决方案1】:

    你在 AppDelegate 中有这个吗?

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    // attempt to extract a token from the url
    
    if ([[url scheme] hasPrefix:@"fb"]) {
        return [FBSession.activeSession handleOpenURL:url];
    }
    .....
    

    您还需要检查您的应用在 AppName-info.plist 中是否有 facebook 的 Url Types 部分

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 1970-01-01
      • 2013-05-17
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 2021-03-18
      相关资源
      最近更新 更多