【问题标题】:Facebook Web Dialog Crashes after clicking on Alert View button (iOS)Facebook Web 对话框在单击警报视图按钮后崩溃 (iOS)
【发布时间】:2013-03-25 07:12:40
【问题描述】:

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

我认为这是一种不屑一顾的观点,但没有足够的关于 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) {
                ........
             }];
        }

    }

}

【问题讨论】:

  • 到目前为止有什么运气吗?我遇到了完全相同的问题。

标签: ios facebook modal-dialog alertview


【解决方案1】:

这是我解决的解决方案 (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,则崩溃问题似乎消失了 - 不知道为什么,但似乎对我有用。

【讨论】:

    【解决方案2】:

    迟到的答案.. 但记录在案.. 我已使用以下方法修复它:

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

    代替:

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

    我认为问题与仍在显示 UIAlertView 时显示的 FBWebDialog 有关。使用 'didDismiss' 可确保在显示网络对话框时警报已经消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 2017-08-16
      • 2020-07-06
      • 2018-11-02
      相关资源
      最近更新 更多