How to invite friends to my application via facebook iOS SDK and Graph API

后端 未结 8 448
攒了一身酷
攒了一身酷 2021-02-01 17:55

I\'m writing an iPhone application.

I want to give the user the option to invite friends to start using my application via Facebook.

More specifically I want to

相关标签:
8条回答
  • 2021-02-01 18:21

    Today with the 3.11 version of the facebook SDK you should use this in order to send an app request to a specific friend.

    NSString *facebookID = @"YOUR_FRIEND_FACEBOOK_ID"
    NSMutableDictionary* params =
    [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];
    
    NSString *message = @"SOME_MESSAGE";
    NSString *title = @"TITLE";
    
    
    FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com
    
    [FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
                                                  message:message
                                                    title:title
                                               parameters:params handler:
     ^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
     {
    
     }];
    
    0 讨论(0)
  • 2021-02-01 18:21

    Make sure your facebook app id is same in both developer page and info in xcode next, enable sandbox mode and must fill canvas url [under app on facebook category] in developer page.

    NSString *facebookID = @"Your friend facebook id";;
        NSMutableDictionary* params =
        [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];
    
        NSString *message = @"SOME_MESSAGE";
        NSString *title = @"TITLE";
    
        [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                      message:message
                    title:title
                    parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                            if (error)
                        {
                        // Case A: Error launching the dialog or sending request.
                            NSLog(@"Error sending request.");
                        }
                        else
                        {
                            if (result == FBWebDialogResultDialogNotCompleted)
                        {
                        // Case B: User clicked the "x" icon
                            NSLog(@"User canceled request.");
                        }
                        else
                        {
                            NSLog(@"Request Sent. %@", params);
                        }
            }}];
    
    0 讨论(0)
  • 2021-02-01 18:21

    You can either use the share dialog to share the Link to download the app to the user's wall, or write custom UI elements and use API Calls to build your own sharing module. Trying using a Facebook iOS SDK to simplify the process or you will have a lot of work to do.

    0 讨论(0)
  • 2021-02-01 18:28

    It's simple you can just write the below code for personalised message and also you can easily select the friend's to whom the request should be sent, it's an straight forward and powerful method.

     [FBWebDialogs
     presentRequestsDialogModallyWithSession:nil
     message:NSLocalizedString(@"FBinviteMessage", nil)
     title:nil
     parameters:nil
     handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
    ];
    

    Just add this six line of code to your Button action method, then the rest will be done by the IOS & FaceBook Inbuilt framework :)

    0 讨论(0)
  • 2021-02-01 18:32
    [FBWebDialogs
     presentRequestsDialogModallyWithSession:nil
     message:@"YOUR_MESSAGE_HERE"
     title:nil
     parameters:nil
     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);
                 }
             }
         }
    }];
    
    0 讨论(0)
  • 2021-02-01 18:34

    Facebook SDK 4.0 introduced "App Invites for iOS". Check it out: https://developers.facebook.com/docs/app-invites/ios

    0 讨论(0)
提交回复
热议问题