3

i am sending app request to facebook friend, so how i can i open app request in UIWebView ?

NSDictionary *parametersDict = @{@"to":@""};

        [FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
                                                      message:@"YouPin"
                                                        title:@"my title"
                                                   parameters:parametersDict
                                                      handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
         {
             if(error)
             {
                 NSLog(@"Some errorr: %@", [error description]);
                 UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Invitiation Sending Failed" message:@"Unable to send inviation at this Moment, please make sure your are connected with internet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                 [alrt show];
             }
             else
             {
                 if (![resultURL query])
                 {
                     [self.navigationController popViewControllerAnimated:YES];
                     return;
                 }

                 NSDictionary *paramsStr = [self parseURLParamsSecond:[resultURL query]];
                 NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
                 for (NSString *paramKey in paramsStr)
                 {
                     if ([paramKey hasPrefix:@"to["])
                     {
                         [recipientIDs addObject:[paramsStr objectForKey:paramKey]];
                     }
                 }
                 if ([paramsStr objectForKey:@"request"])
                 {
                     NSLog(@"Request ID: %@", [paramsStr objectForKey:@"request"]);
                 }
                 if ([recipientIDs count] > 0)
                 {
                     NSLog(@"Recipient ID(s): %@", recipientIDs);
                     UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Invitation(s) sent successfuly!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                     alrt.tag = 10;
                     [alrt show];
                 }
             }
         }friendCache:nil];

    - (NSDictionary *)parseURLParamsSecond:(NSString *)query
    {
        NSArray *pairs = [query componentsSeparatedByString:@"&"];
        NSMutableDictionary *paramsSECOND = [[NSMutableDictionary alloc] init];
        for (NSString *pair in pairs)
        {
            NSArray *kv = [pair componentsSeparatedByString:@"="];

            [paramsSECOND setObject:[[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
                             forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        }

        return paramsSECOND;
    }

i am sending app request to facebook friend, so how i can i open app request in UIWebView ?

user3829315
  • 169
  • 2
  • 10

1 Answers1

1

For inviting users you can use the following code after adding the facebook-sdk

[FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
message:@"Your invite message"
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                      if (error) {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"Error publishing story: %@", error.description);
                                      } else {
                                          if (result == FBWebDialogResultDialogNotCompleted) {
                                              // User canceled.
                                              NSLog(@"User cancelled.");
                                          } else {
                                              // Handle the publish feed callback




                                              } 

                                    }


}];

/////////////////////////

Showing app request in webview : Send facebookId of your friend and your message.

- (void)sendAppRequestToFacebookFriend:(NSString*)message andFacebookId:(NSString*)friendFBId {


NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                message, @"message",
                               @"", @"redirect_url",
                               friendFBId,@"to",
                               nil];


[FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
 message:message
 title:@"App Title App"
 parameters:params
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {

     if (!error) {


         if (result == FBWebDialogResultDialogNotCompleted) {





         }
         else if([[resultURL description] hasPrefix:@"fbconnect://success?request="]) {
             //code after success
            } 

     } 

 }
  ];

}
yoshiiiiiiii
  • 953
  • 8
  • 20
  • that's ok but how can pass this url to webview. how can open app request in webview. – user3829315 Feb 11 '15 at 10:47
  • hey brother !!! i have FacebookHelper.h & m file and sharedFacebookHelper.session even undeclare identifer as error i got, what to do ? – user3829315 Feb 12 '15 at 06:13
  • In the Block of -presentRequestsDialogModallyWithSession:sharedFacebookHelper.delegate.session, i got undeclare identifier for 'shareFacebookHelper.delegate.session'. – user3829315 Feb 12 '15 at 06:25
  • Crash : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBDialog initWithURL:params:isViewInvisible:frictionlessSettings:delegate:]: unrecognized selector sent to instance 0x78ed0260'. – user3829315 Feb 12 '15 at 06:31
  • http://stackoverflow.com/questions/18345283/facebook-ios-sdk-presentfeeddialogmodallywithsession-crashes – yoshiiiiiiii Feb 12 '15 at 06:34
  • brother, not getting answered properly.... code is not working properly even, crash on run – user3829315 Feb 12 '15 at 06:41