ios - 通过 Safari 或 FB App 登录 Facebook 无效

标签 ios facebook facebook-graph-api parse-platform

当用户在 iOS8 设置中登录 Facebook 时,此方法非常有效。

但如果他没有,它会尝试使用 Safari 或 Facebook iOS 应用程序登录,一旦用户被重定向回应用程序,它只会显示这条记录的消息,而不是让用户登录。

我正在使用 Parse.com SDK。

消息已记录

NSLog(@"Uh oh. The user cancelled the Facebook login.");

Facebook 登录方法

-(void)loginButtonPressed
{
      [PFFacebookUtils initializeFacebook];

        NSArray *permissionsArray = @[@"user_about_me"];

        // Login PFUser using Facebook
        [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {

            if (!user) {
                NSString *errorMessage = nil;
                if (!error) {

                    NSLog(@"Uh oh. The user cancelled the Facebook login.");
                    errorMessage = @"Uh oh. The user cancelled the Facebook login.";
                } else {
                    NSLog(@"Uh oh. An error occurred: %@", error);
                    errorMessage = [error localizedDescription];
                }

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error"
                                                                message:errorMessage
                                                               delegate:nil
                                                      cancelButtonTitle:nil
                                                      otherButtonTitles:@"Dismiss", nil];
                [alert show];

            } else {
                if (user.isNew) {
                    [self dismissViewControllerAnimated:YES completion:nil];

                    NSLog(@"User with facebook signed up and logged in!");
                } else {
                    [self dismissViewControllerAnimated:YES completion:nil];

                    NSLog(@"User with facebook logged in!");
                }
               // [self _presentUserDetailsViewControllerAnimated:YES];
        }];

}

最佳答案

AppDelegate.m 中添加这一行解决了这个问题。

- (void)applicationDidBecomeActive:(UIApplication *)application {

    [FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];

    // 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.
}

关于ios - 通过 Safari 或 FB App 登录 Facebook 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26354801/

相关文章:

ios - 将从iPad/iPhone拍摄的图像保存到sql server数据库base64

ios - 使用 JSON 解析指定的 Twitter 提要

facebook-graph-api - Facebook Graph API 'module' 对象没有属性 'GraphAPI'

facebook-graph-api - Facebook FQL 查询和多查询的限制是什么(多查询的最大数量和速率限制)

Android Facebook - 如何获得帖子的点赞数?

ios - 在ios中旋转一条线

ios - 比较 Obj-C 中的对象,为什么它们不匹配?

php - 为什么在IE中使用XFBML注册插件会出现空白?

facebook - '发生未知错误 .' when updating a facebook group' s cover_url

Facebook Graph API - 非好友公共(public)相册的空 JSON 数组