We can share post in Facebook by using following steps:
Add one button on ViewController and give action to it.
Import #import <Social/Social.h>
Now in button action write following code.
- (IBAction)facebookButtonAction:(id)sender {
SLComposeViewController *controller = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock =
^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(@"Cancelled");
}
else
{
NSLog(@"Done");
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler =myBlock;
//Adding Text to the facebook post
[controller setInitialText:@"My test post"];
//Adding URL to the facebook post
[controller addURL:[NSURL URLWithString:@"http://www.test.com"]];
[self presentViewController:controller animated:YES completion:nil];
}
0 Comment(s)