问题
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 present a dialog that will let the user to select specific friends to invite.
How can I do this?
Thanks.
回答1:
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 :)
回答2:
You can do something like this:
Facebook* facebook =
[[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_APP_ID" andDelegate:self];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"My Title", @"title",
@"Come check out my app.", @"message",
@"FACEBOOK_USER_ID", @"to",
nil];
[facebook dialog:@"apprequests" andParams:params andDelegate:self];
You can see the list of possible parameters at this page (scroll down): http://developers.facebook.com/docs/reference/dialogs/requests/
回答3:
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)
{
}];
回答4:
Facebook SDK 4.0 introduced "App Invites for iOS". Check it out: https://developers.facebook.com/docs/app-invites/ios
回答5:
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);
}
}}];
回答6:
To send facebook app invites, you need to first add details of your app here.. https://developers.facebook.com/quickstarts/?platform=app-links-host
In Swift 2.2, XCode 7.3 and FBSDK 4.1
import FBSDKShareKit
import FBSDKCoreKit
import FBSDKLoginKit
Add
FBSDKAppInviteDialogDelegate
with your ViewController class.func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) { print("Initiation sent") } func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) { print("\(error)") }
let content = FBSDKAppInviteContent(); content.appLinkURL = NSURL(string: "fb link that you get in above developers facebook url"); //"https:// fb.me/1775107252721102" in my case FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self);
回答7:
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.
回答8:
[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);
}
}
}
}];
来源:https://stackoverflow.com/questions/10834140/how-to-invite-friends-to-my-application-via-facebook-ios-sdk-and-graph-api