Reputation: 165
I am pretty new at incorporating Facebook into iOS apps. I have read 3 books, studied the Facebook examples, and studies the Facebook tutorials, and I don't understand Facebook integration. I understand how to register the app with Facebook, but what I don't understand is the code to post text and a picture to a user's news feed. I have tried to understand Facebook's tutorials, but they are all based on Xcode and iOS versions which are not current. Facebook's tutorials are also not consistent (e.g., the login tutorial does not match variables with the posting tutorial, etc.). I do understand how to add text to "initialText", but it's against Facebook policy to provide default text in this variable. Can anyone explain how to publish text and a picture to a user's news feed in Xcode?
Thanx!
Upvotes: 1
Views: 270
Reputation: 1331
Have you tried this one?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"ResultCancelled");
} else
{
NSLog(@"ResultSuccess");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:@"Learn iOS6 Social Framework integration"];
[controller addURL:[NSURL URLWithString:@"http://google.com"]];
[controller addImage:[UIImage imageNamed:@"myimage.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
//NSLog(@"UnAvailable");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook"
message:[NSStringstringWithFormat:@"The application cannot post message at the moment. Please login under setting section with your Facebook account."]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Upvotes: 1
Reputation: 708
import social framework in your project.
- (void)ShareOnFB
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Cancelled");
} else
{
NSLog(@"Done");
//Adding the Text to the facebook post value from iOS
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
NSString *fb=[NSString stringWithFormat:@"you can add your text hereand change it as and when needed"];
[controller setInitialText:fb];
//Adding the Image to the facebook post value from iOS
[controller addImage:yourImageView.image];
[self presentViewController:controller animated:YES completion:Nil];
}
Upvotes: 0