Introduction
Posting text on a friend’s wall is a great way to share content with them. With the latest Facebook SDK for iOS, it is now easier than ever to post text on a friend’s wall. In this article, we will discuss how to post text on a friend’s wall using the latest Facebook SDK for iOS. We will also discuss some tips and tricks to make the process easier.
Solution
//Step 1:
//Create a Facebook App and get the App ID.
//Step 2:
//Download the latest Facebook SDK for iOS and add it to your project.
//Step 3:
//Add the following code to your project:
//Import the Facebook SDK
#import
#import
//Create a link content object
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@”http://www.example.com”];
content.contentTitle = @”My App”;
content.contentDescription = @”Check out my app!”;
//Create a share dialog
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeFeedBrowser; //or FBSDKShareDialogModeNative
[dialog show];
//Step 4:
//Handle the response from the dialog
– (void)sharer:(id
//Post was successful
}
– (void)sharer:(id
//Post failed
}
– (void)sharerDidCancel:(id
//Post was cancelled
}
You can post on friends wall by using FBWebDialogs
class of Facebook SDK
. For that you need friends facebook id in parameters in dictionary as below
NSMutableDictionary *parmaDic = [NSMutableDictionary dictionaryWithCapacity:5];
[parmaDic setObject:link forKey:@"link"]; // if you want send picture
[parmaDic setObject:@"NAME" forKey:@"name"]; // if you want to display name
[parmaDic setObject:message forKey:@"description"]; // if you want to display description
[parmaDic setObject:@"FRIEND_FACEBOOK_ID" forKey:@"to"];
[parmaDic setObject:@"LOGO_URL" forKey:@"picture"]; // if you want to send App logo
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:parmaDic 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(@"Successfully Invited.");
}
}
}];
4
solved How to post text on friends wall using latest facebook sdk in IOS