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

标签 objective-c ios facebook uialertview

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

_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.

如果我将这段代码连接到一个按钮,它就可以工作。但是,当我将它放在以下方法中时:

- (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.

    }
}

它不起作用..

谁能解释一下为什么会这样?当我说它不起作用时,我的意思是对话框在关闭之前非常短暂地显示。该应用程序不会崩溃。

最佳答案

等待 1 秒不是解决方案,也不能真正解决问题。

问题是你听:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

应该是:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

因为在 clickedButtonAtIndex 函数中 View 没有关闭,这可能会导致问题。

编辑: 为了让它在 iOS 4 中工作,将你的 facebook 登录调用添加到一个方法中,并在 didDismissWithButtonIndex 中调用以下函数:

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

关于objective-c - Facebook 登录对话框不适用于 UIAlertView,但适用于 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309289/

相关文章:

ios - FBRequestConnection startForMyFriendsWithCompletionHandler 不带所有安装了该应用程序的 friend - iOS

ios - 检测整个屏幕上的触摸

ios - 如何在没有深度值的情况下使用 SceneKit 的 unprojectPoint 将 2D 点转换为 3D?

php - 如何在 php/css 页面上添加类似 facebook 的按钮?

ios - 如何修复 iOS 7 中的状态栏重叠问题

objective-c - 如何识别可变对象?

objective-c - 如何检查objectForKey返回的NSString是否为 ""objective-c

ios - 创建 'always logged in' IOS 应用程序最安全的方法是什么?

facebook - 我可以将 Facebook Comments 与 native WordPress 评论系统集成吗?

python - Django-Allauth Facebook 集成 - 请求单独发布到用户墙上的权限