Search code examples
iosobjective-cfacebookfacebook-graph-apifacebook-ios-sdk

How to send request using FBWebDialogs in Objective c


I am creating one game in which user can send request to his friends using FBdialogs. I am using the following code for that.

    NSError *error;
    NSData *jsonData = [NSJSONSerialization
                        dataWithJSONObject:@{
                        @"social_karma": @"5",
                        @"badge_of_awesomeness": @"1"}
                        options:0
                        error:&error];
    if (!jsonData) {
        NSLog(@"JSON error: %@", error);
        return;
    }

    NSString *giftStr = [[NSString alloc]
                         initWithData:jsonData
                         encoding:NSUTF8StringEncoding];

    NSMutableDictionary* params = [@{@"data" : giftStr} mutableCopy];


    // Display the requests dialog
    [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);
                 }
             }
         }
     }];

This code is sending request successfully to selected user and shows request ID also. But when I check in friends update. It is not showing any request in his update.

can any one tell me what is wrong in this code? Or should any other method to send request to friends?


Solution

  • Pls check -

    1. App Settings

      You may have forgotten to put the settings for your iOS app into the settings for your app in your App Dashboard

    2. Sandbox Mode

      Ensure that the sandbox mode is OFF in the App Settings.