Min Huang
Min Huang

Reputation: 31

iOS Facebook share

After getting grantedPermissions "publish_actions", now I want to users want user to send a message and a image(local generated) to their Facebook timelines without leave current view.

I have tried FBSDKShareAPI interface, but this is not the effect I want. I hope to implement one status with one message and one image. How can I do?

FBSDKSharePhoto* photo = [[FBSDKSharePhoto alloc]init];
photo.image = self.shareImage;
photo.userGenerated = YES;

FBSDKSharePhotoContent * content = [[FBSDKSharePhotoContent alloc]init];
content.photos = @[photo];

if ([[FBSDKAccessToken currentAccessToken].permissions containsObject:@"publish_actions"]) {
    FBSDKShareAPI * shareApi = [[FBSDKShareAPI alloc]init];
    shareApi.message = self.tf.text;
    [shareApi createOpenGraphObject:object];
    [FBSDKShareAPI shareWithContent:content delegate:self];
    [shareApi share];
  }

Upvotes: 2

Views: 883

Answers (1)

bangdel
bangdel

Reputation: 2553

You are sharing the same content twice which is probably why you aren't able to get one status message with one image (and instead getting two):

[FBSDKShareAPI shareWithContent:content delegate:self];
[shareApi share];

And you probably don't need to create an open graph object for the same. Try this:

NSURL *imageURL = [NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/en/d/d3/Nasa_mer_marvin.jpg"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]]; // taking image from Wikipedia for example purposes
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image; // photo.image = self.shareImage;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
if ([[FBSDKAccessToken currentAccessToken].permissions containsObject:@"publish_actions"]) {
    FBSDKShareAPI * shareApi = [[FBSDKShareAPI alloc]init];
    shareApi.message = @"Lorem Ipsum Dolor Sit Amet"; // shareApi.message = self.tf.text;
    shareApi.shareContent = content;
    [shareApi share];
}

Upvotes: 4

Related Questions