ios - 单击“警报 View ”按钮后 Facebook Web 对话框崩溃 (iOS)

标签 ios facebook modal-dialog alertview

我正在尝试将 iOS 应用程序与 Facebook 集成。登录和大多数功能运行良好,但当我尝试让 FBWebDialogs 共享用户发布的内容时,我遇到了一个小问题。如果在发布(调用函数)后直接调用它,它效果很好,但当我尝试从警报 View 执行相同操作时,它会崩溃,它刚刚开始出现,然后在完全加载之前突然消失,而不会破坏应用程序,并且不会引发任何错误。当用户在 iPhone 设置中登录时,它使用 iOS 6 中的新 Facebook 功能来工作,该功能具有 native View 而不是 FBWebDialogs。 我使用第三方库来自定义警报 View ,但它与标准警报 View 的作用相同。

我认为这是一种不屑一顾的观点,但对 iOS 的了解还不够,无法确定。任何想法?。谢谢。

这就是代码:

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

    switch (buttonIndex)
    {
        case 1:
        {
            [self sharePostOnFacebook];
            break;
        }
        default:
            break;
    }
}

调用了下一个方法,但模态视图永远不会完全显示。它只是闪烁然后消失

-(void) sharePostOnFacebook
{
    if (shareData !=nil && [[shareData objectForKey:@"success"] boolValue])
    {
        NSString *caption = [shareData objectForKey:@"caption"];
        . ..........


        BOOL displayedNativeDialog =
        [FBNativeDialogs
         presentShareDialogModallyFrom:self
         initialText:description
         image:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picture]]]
         url:[NSURL URLWithString:link]
         handler:^(FBNativeDialogResult result, NSError *error) {

             .........
         }];
        // Fallback, show the view controller that will post using me/feed
        if (!displayedNativeDialog)
        {
            [[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];

            // Put together the dialog parameters
            NSMutableDictionary *params =
            [NSMutableDictionary dictionaryWithObjectsAndKeys:
             .............
             nil];

            FBSession *activeSession = [FBSession activeSession];
            // Invoke the dialog
            [FBWebDialogs presentFeedDialogModallyWithSession:activeSession
                                                   parameters:params
                                                      handler:
             ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                ........
             }];
        }

    }

}

最佳答案

这是我解决的解决方案 ( https://developers.facebook.com/docs/howtos/send-requests-using-ios-sdk/ )。

关键似乎是延迟对 FBWebDialog 的调用。

[self performSelector:@selector(sendRequest) withObject:nil afterDelay:0.5];

sendRequest 可以是

- (void)sendFlyerFloRequestToFriends
{
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
   [FBWebDialogs presentRequestsDialogModallyWithSession: ...

如果使用performSelector(使用延迟)调用presentRequestsDialogModallyWithSession,那么崩溃问题似乎消失了 - 不知道为什么,但似乎对我有效。

关于ios - 单击“警报 View ”按钮后 Facebook Web 对话框崩溃 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15790422/

相关文章:

php - 通过 PHP SDK 验证 Facebook API 访问 token 和用户 ID?

Angular 2 ng-bootstrap 模态

ios - 如何通过拖动 ImageView 的右角来调整 ImageView 的大小和旋转 ImageView

facebook - FB 实时 API 不/不一致地通知某些连接(音乐、电影、书籍、电视)

iphone - 那么 CALayer 不包含 View 的内容位图?

php - 将 facebook 应用程序 key 存储在 mysql 数据库中安全吗?

javascript - Gatsby 在单击按钮时打开模态窗口

javascript - Angular 6 - 自定义模态窗口内的嵌套组件

ios - Xcode 进程启动失败 : Security

ios - 有没有一种方法可以在不请求相机权限的情况下创建一个简单的 iOS 相机实例? ( swift 5.1)