简体   繁体   中英

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];
  }

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM