Well, first of all, you should add Social.framework to your project.
Step 2 : you need to import two classes. Import the required classes.
#import <Social/Social.h> #import <Accounts/Accounts.h>
Step 3 I am advancing on the assumption that you have a button for Facebook in your application. On the button, click these lines. You made.: -)
- (IBAction)facebookButtonClicked:(id)sender { if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook]) { // Facebook Service Type is Available SLComposeViewController *slVC = [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook]; SLComposeViewControllerCompletionHandler handler = ^(SLComposeViewControllerResult result) { if (result == SLComposeViewControllerResultCancelled) { NSLog(@"Cancelled"); } else { NSLog(@"Done"); } [slVC dismissViewControllerAnimated:YES completion:Nil]; }; slVC.completionHandler = handler; [slVC setInitialText:@"Test Post from iOS6"]; [slVC addURL:[NSURL URLWithString:@"http://www.apple.com"]]; [slVC addImage:[UIImage imageNamed:@"someimage.png"]]; [self presentViewController:slVC animated:YES completion:Nil]; } else { NSLog(@"Service Unavailable!!!"); } }
The above are the main steps. For more information, you can contact This .
Change For Facebook user information, see.
Happy coding. :-)
source share