2

在这里,我试图从我的应用程序中邀请 Facebook 朋友。

我跟着这个答案

它可以正常工作webDialog。但是当我单击发送按钮时,它会给出异常

WebKit 在 webView:decidePolicyForNavigationAction:request:frame:decisionListener:delegate:+[NSInvocation _invocationWithMethodSignature:frame:] 中丢弃了一个未捕获的异常:方法签名参数不能为 nil

我无法理解我的代码有什么问题。这是我正在使用的代码

-(void)inviteFriends
    {
        if ([[FBSession activeSession] isOpen])
        {
            NSMutableDictionary* params =  [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
            [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                                          message:@"Sending from facebook chat"
                                                            title:nil
                                                       parameters:params
                                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
             {
                 if (error)
                 {
                     [self requestFailedWithError:error];
                 }
                 else
                 {
                     if (result == FBWebDialogResultDialogNotCompleted)
                     {
                         [self requestFailedWithError:nil];
                     }
                     else if([[resultURL description] hasPrefix:@"fbconnect://success?request="])
                     {
                         // Facebook returns FBWebDialogResultDialogCompleted even user
                         // presses "Cancel" button, so we differentiate it on the basis of
                         // url value, since it returns "Request" when we ACTUALLY
                         // completes Dialog
                         [self requestSucceeded];
                     }
                     else
                     {
                         // User Cancelled the dialog
                         [self requestFailedWithError:nil];
                     }
                 }
             }
             ];

        }
        else
        {
            /*
             * open a new session with publish permission
             */
            [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"]
                                               defaultAudience:FBSessionDefaultAudienceFriends
                                                  allowLoginUI:YES
                                             completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
             {
                 if (!error && status == FBSessionStateOpen)
                 {
                     NSMutableDictionary* params =   [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
                     [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                                                   message:@"Sending from facebook chat"
                                                                     title:nil
                                                                parameters:params
                                                                   handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
                      {
                          if (error)
                          {
                              [self requestFailedWithError:error];
                          }
                          else
                          {
                              if (result == FBWebDialogResultDialogNotCompleted)
                              {
                                  [self requestFailedWithError:nil];
                              }
                              else if([[resultURL description] hasPrefix:@"fbconnect://success?request="])
                              {
                                  // Facebook returns FBWebDialogResultDialogCompleted even user
                                  // presses "Cancel" button, so we differentiate it on the basis of
                                  // url value, since it returns "Request" when we ACTUALLY
                                  // completes Dialog
                                  [self requestSucceeded];
                              }
                              else
                              {
                                  // User Cancelled the dialog
                                  [self requestFailedWithError:nil];
                              }

                          }
                      }];
                 }
                 else
                 {
                     [self requestFailedWithError:error];
                 }
             }];
        }

    }


 // These methods for requestSucceeded and requestFailed 

    - (void)requestSucceeded
    {
        NSLog(@"requestSucceeded1");
        id owner = [_fbDelegate class];
        SEL selector = NSSelectorFromString(@"OnFBSuccess");
        NSMethodSignature *sig = [owner instanceMethodSignatureForSelector:selector];
         _callback = [NSInvocation invocationWithMethodSignature:sig];
        [_callback setTarget:owner];
        [_callback setSelector:selector];

        [_callback invokeWithTarget:_fbDelegate];
    }

    - (void)requestFailedWithError:(NSError *)error
    {
        NSLog(@"requestFailed");
        id owner = [_fbDelegate class];
        SEL selector = NSSelectorFromString(@"OnFBFailed:");
        NSMethodSignature *sig = [owner instanceMethodSignatureForSelector:selector];
       _callback = [NSInvocation invocationWithMethodSignature:sig];
        [_callback setTarget:owner];
        [_callback setSelector:selector];
        [_callback setArgument:&error atIndex:2];
        [_callback invokeWithTarget:_fbDelegate];
    }

    -(void)OnFBSuccess
    {
        NSLog(@"successful");

    }

    -(void)OnFBFailed:(NSError *)error
    {
        if(error == nil)
            NSLog(@"user cancelled");
        else
            NSLog(@"failed");
    }

@protocol FBLoginDelegate <NSObject>也在 viewController.h. 我不知道代码有什么问题。谁能帮我摆脱这个问题? 这是与朋友列表一起出现的 webDialog,但是当我单击发送时,它不会发送任何消息。

4

0 回答 0