Nila
Nila

Reputation: 49

How can share images on facebook from an iphone app using social framework in ios 6.0?

I used the code given below. But it only post image to facebook.

UIImage *image = [UIImage imageNamed:@"testimage.png"];
    NSString *caption = @"Gud Mng";
    NSArray *activityItems = @[image, caption];
    // Initialize Activity View Controller
    UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    // Present Activity View Controller
    [self presentViewController:vc animated:YES completion:nil];

Upvotes: 3

Views: 1052

Answers (1)

Durgaprasad
Durgaprasad

Reputation: 1951

Add social framework. Import in your view controller.

SLComposeViewController *socialVc=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSData *data = UIImageJPEGRepresentation(self.defaultImageView.image, 1.0);
[socialVc addImage:[UIImage imageWithData:data]];


[socialVc setInitialText:[NSString    stringWithFormat:@"%@",self.captionTextFeild.text]];
[socialVc addURL:[NSURL URLWithString:@"via www.coderit.com"]];
[self.navigationController presentViewController:socialVc animated:YES completion:nil];

Upvotes: 1

Related Questions