In my application, I use FBWebDialogs to request the sen application for facebook friends, and I am doing this successfully. My problem is that I cannot handle the FBWebDialogs button. In the code below, I can detect the X button and the cancel button, but when I select the submit button, it still gives the NSLog(@"User canceled request."); log NSLog(@"User canceled request."); . I use the codes exactly indicated in the facebook documentation. What is my mistake?
[FBWebDialogs presentRequestsDialogModallyWithSession:nil message:@"Learn how to make your iOS apps social." title:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { if (error) { // Error launching the dialog or sending the request. NSLog(@"Error sending request."); } else { if (result == FBWebDialogResultDialogNotCompleted) { // User clicked the "x" icon NSLog(@"User canceled request."); } else { // Handle the send request callback NSDictionary *urlParams = [self parseURLParams:[resultURL query]]; if (![urlParams valueForKey:@"request"]) { // User clicked the Cancel button NSLog(@"User canceled request."); } else { // User clicked the Send button NSString *requestID = [urlParams valueForKey:@"request"]; NSLog(@"Request ID: %@", requestID); } } } }];
And I have a parseURLParams function:
- (NSDictionary*)parseURLParams:(NSString *)query { NSArray *pairs = [query componentsSeparatedByString:@"&"]; NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; for (NSString *pair in pairs) { NSArray *kv = [pair componentsSeparatedByString:@"="]; NSString *val = [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [params setObject:val forKey:[kv objectAtIndex:0]]; } return params; }
source share