Facebook SDK:登录行为不正确。在会话状态下打开safari登录窗口“打开”

时间:2014-02-03 10:52:43

标签: ios facebook facebook-graph-api facebook-ios-sdk

情况:
人员登录FBApp但不登录系统FB帐户。

我做什么:
我问readPermissionspublishPermissions。之后,我发送人员身份请求(身份证,姓名,用户名,profile_picture_url)。

行为:
一切正常,facebook ios sdk两次去fb app(每个请求 - 阅读和发布),然后出现奇迹。 我要求提供个人身份并查看Facebook窗口,建议下载iPhone的fb应用程序(fb应用程序已经在它上面!)并要求我登录网站。我认为这是一个safari登录。

代码:

/*login here*/
            if([_facebookSession state] == FBSessionStateCreated){
                [FBSession openActiveSessionWithReadPermissions:readPermissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                    if (error || status == FBSessionStateClosedLoginFailed){
                        [_facebookSession openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                            if (error || status == FBSessionStateClosedLoginFailed){
                                LoginFailedBlock(YES);
                            }
                            else
                            if (error == nil && status == FBSessionStateOpen){
                                _facebookSession = session;
                                LoginSucessBlock(YES);
                            }
                        }];
                    }else{
                        dispatch_async(dispatch_get_current_queue(), ^{
                            [FBSession openActiveSessionWithPublishPermissions:publishPermissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                if (error == nil && status == FBSessionStateOpen){
                                    _facebookSession = session;
                                    LoginSucessBlock(YES);
                                }
                            }];
                        });
                    }
                }];



/*request for person identity*/
/*SOMEWHERE HERE A SAFARI LOGIN WINDOW APPEARS*/
     [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> result, NSError *error) {
            if (error){
                ErrorBlock(error);
            }
            else{
                if ([result id] && [result name]){
                    NSDictionary* resultDictionary = @{@"id":result.id,
                                                       @"name":result.name,
                                                       @"username":result.username,
                                                       @"picture":result.link,
                                                       };
                    AfterLoadUserInfoBlock(YES,resultDictionary);
                }
                else{
                    AfterLoadUserInfoBlock(NO,nil);
                }
            }
        }];

1 个答案:

答案 0 :(得分:0)

在视图控制器中:

self.loginview = [[FBLoginView alloc] init];
self.loginview.frame = CGRectMake(-500, -500, 0, 0);
[self.view addSubview:self.loginview];
self.loginview.delegate = self;
[loginview setReadPermissions:@[@"basic_info",@"email"]];
[loginview setDelegate:self];

 -(IBAction)loginWithFB:(id)sender{
    for(id object in self.loginview.subviews){
        if([[object class] isSubclassOfClass:[UIButton class]]){
            UIButton* button = (UIButton*)object;
            [button sendActionsForControlEvents:UIControlEventTouchUpInside];
        }
    }
}
在appdelegate中

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    // Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
    BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];

    // You can add your app-specific url handling code here if needed

    return wasHandled;
}

然后请在您的developer.facebook.com中使用您的包ID注册您的应用程序,最后您将获得一个ID并在您的plist文件中进行配置