Skip to content

Instantly share code, notes, and snippets.

@anuragsolanki
Created September 2, 2012 06:01
Show Gist options
  • Save anuragsolanki/3595224 to your computer and use it in GitHub Desktop.
Save anuragsolanki/3595224 to your computer and use it in GitHub Desktop.
Integrating Facebook in iOS 6
#import "Social/Social.h"
#import "Accounts/Accounts.h"
-(IBAction)postToFaceBook:(id)sender{
//Deprecated in iOS6
/*
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType];
NSLog(@"%@, %@", account.username, account.description);
}];
*/
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
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;
[controller setInitialText:@"Test Post from iOS-6-facebook-library"];
[controller addURL:[NSURL URLWithString:@"http://www.vinsol.com"]];
[controller addImage:[UIImage imageNamed:@"fb.png"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else {
NSLog(@"UnAvailable");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment