Well, First of all you have to add the Social.framework
in to your project.
Step 2 : You need to import two classes.Import the needed classes.
#import <Social/Social.h>
#import <Accounts/Accounts.h>
Step 3 : I am going forward in the assumption that you have a button for Facebook in your app. At the button click write these lines. You are done. :-)
- (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 given is the basic steps. For more you can refer This.
Edit : For Facebook user information refer this answer.
Happy Coding. :-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…