2

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.

Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
  • 1
    `OnFBSuccess` and `OnFBFailed` should be move to your viewcontroller. Visit the blog link and see the code resides inside viewcontroller: http://journeytoios.wordpress.com/2014/09/03/facebook-invite-friend-implementation/ – NeverHopeless Sep 04 '14 at 05:27
  • @NeverHopeless,Added `OnFBSuccess` and `OnFBFailed` in `viewController.m`. but still not working. It resolved the exception `method signature argument cannot be nil`.But not sending message yet. – Sushil Sharma Sep 04 '14 at 05:37
  • Di you setup appdelegate and plist correctly ? and also did you used a correct facebook application id ? – NeverHopeless Sep 04 '14 at 06:20
  • @NeverHopeless,check i have added screenshot in question – Sushil Sharma Sep 04 '14 at 11:01
  • did you check it is coming in `OnFBSuccess` function ? If it is then code is fine, you have to check your application settings on developer.facebook.com. – NeverHopeless Sep 04 '14 at 20:29
  • @NeverHopeless ,Yes it is calling `OnFBSuccess` method.Now what to do? – Sushil Sharma Sep 05 '14 at 04:08
  • It means code has no issue. Please check developer.facebook.com and verify that your application setup on facebook correctly and try to toggle the sandbox mode. – NeverHopeless Sep 05 '14 at 06:04
  • @NeverHopeless, Hey dear.. This worked for me... Now if i want to post on friend's wall.How is this possible with web dialog. – Sushil Sharma Nov 17 '14 at 09:21

0 Answers0