PFFacebookUtils - 重新授权用户后隐藏进度HUD

时间:2014-02-20 21:36:45

标签: ios facebook parse-platform

在我的iOS应用中,以下代码使用Facebook记录用户:

- (IBAction)facebookAuthButtonPressed:(id)sender {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [PFFacebookUtils logInWithPermissions:@[@"basic_info", @"user_about_me"] block:^(PFUser *appUser, NSError *error) {
        NSLog(@"Login succeeded");//todo: other app logic
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (appUser) {
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            [PFFacebookUtils reauthorizeUser:[PFUser currentUser] withPublishPermissions:@[@"publish_stream"] audience:FBSessionDefaultAudienceFriends block:^(BOOL succeeded, NSError *error) {
                [MBProgressHUD hideHUDForView:self.view animated:YES];
                NSLog(@"Reauthorize succeeded");//todo: other app logic
            }];
        } else {
            NSLog(@"Reauthorize failed");//todo: other app logic
            //todo show alert
        }
    }];
}

我在控制台中看到Login succeeded,然后出现要求我授权的网页。单击“确定”后,应用程序再次出现,显示进度提示,并且永远不会消失。 我从未在控制台中看到“重新授权成功”或“重新授权失败”。

传递重新授权的块是否在与主线程进行重新授权调用的线程不同的线程上调用?

更新 我试过跟随它仍然无法正常工作。控制台上仅打印Login succeeded。我在区块内的断点永远不会到达。

- (IBAction)facebookAuthButtonPressed:(id)sender {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [PFFacebookUtils logInWithPermissions:@[@"basic_info", @"user_about_me"] block:^(PFUser *appUser, NSError *error) {
        NSLog(@"Login succeeded");//todo: other app logic
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (appUser) {
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            //todo the user may decide not to authorize the app to post on their behalf. We need to handle this. During sharing for instance we may have to let the user know that they cant share since they haven't authorized the app andgive them option to authorize.
            [PFFacebookUtils reauthorizeUser:[PFUser currentUser] withPublishPermissions:@[@"publish_stream"] audience:FBSessionDefaultAudienceFriends block: ^ (BOOL succeeded, NSError *error){
//             [self performSelectorOnMainThread:@selector(facebookAuthorizationCompleted) withObject:nil waitUntilDone:NO];
                NSLog(@"Reauthorize finished");
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSLog(@"In dispatch");
                });
            }];
        } else {
            NSLog(@"Login failed");//todo: other app logic
            //todo show alert
        }
    }];
}

更新2 我在控制台中发现了以下内容:

2014-02-21 09:59:58.679 CrossPlex [13839:740b]无法endBackgroundTask:标识符b不存在后台任务,或者它可能已经结束。中断UIApplicationEndBackgroundTaskError()以进行调试。

似乎它与应用程序将控制转移到Safari,然后Safari在重新授权过程中将控制权转移回应用程序有关。

0 个答案:

没有答案