Sending Invitation to Facebook Friends with Facebook SDK from IOS App

1.2k views Asked by At

Here I am trying to invite Facebook friends from my app.

I followed this answer

It works fine with webDialog .But when I click on send button it gives exception

WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: +[NSInvocation _invocationWithMethodSignature:frame:]: method signature argument cannot be nil

I am unable to understand whats wrong with my code. Here is my code which i am using

-(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");
    }

I am also declaring @protocol FBLoginDelegate <NSObject> in viewController.h. I don't know whats wrong with the code. Can anyone please help me come out of this issue? Here is the webDialog appearing with friend list but when i click on send.It doesn't send any message.

0

There are 0 answers