Facebook登录对话框不适用于UIAlertView,但适用于UIButton

Jac*_*ins 0 facebook objective-c uialertview ios

我有这段代码用于显示登录对话框/发布到用户墙:

_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
    self.loginDialog = nil;
    loginDialog = [[FBLoginDialog alloc] init]; 
    [_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
    [self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
Run Code Online (Sandbox Code Playgroud)

如果我将此代码连接到按钮,它可以工作.但是,当我将它放在以下方法中时:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        NSLog(@"No");
    }
    else
    {       
        _posting = YES;
        // If we're not logged in, log in first...
        if (![_session isConnected]) {
            self.loginDialog = nil;
            _loginDialog = [[FBLoginDialog alloc] init];    
            [_loginDialog show];
        }
        // If we have a session and a name, post to the wall!
        else if (_facebookName != nil) {
            [self postToWall];
        }
        // Otherwise, we don't have a name yet, just wait for that to come through.

    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用..

任何人都可以解释为什么会这样吗?当我说它不起作用时,我的意思是在关闭之前对话框显示非常简短.该应用程序不会崩溃.

Rol*_*som 7

等待1秒不是解决方案,实际上并没有解决问题.

问题是你听:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

应该是:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

因为在clickedButtonAtIndex功能上视图没有关闭,这可能会导致问题.

编辑:要使其在iOS 4中工作,请将facebook登录调用添加到方法中,并在didDismissWithButtonIndex中调用以下函数:

[self performSelectorOnMainThread:@selector(facebookOpenAction)withObject:nil waitUntilDone:NO];