Search code examples
iosfacebookfacebook-share

Share an image from my app to facebook


I have a movie quiz app, and I want users to share the movie scene image that they are stuck on to Facebook so they can ask their friends for help.

With Facebook's recent changes I am struggling to figure out how to post the image that the user is up to.

All the movie scene images are stored in the app so there is no URL.

I am trying to get the image from my array like this:

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.imageURL = [NSURL fileURLWithPathComponents:[[mainInfoArray objectAtIndex:index] objectForKey:PHONE_IMAGE]];

but it does not work. Any ideas please to get this to work? Thank You


Solution

  • First, you create the content, then you create a share-button with that content.

    FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
    photo.image = image;
    photo.userGenerated = YES;
    FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
    content.photos = @[photo];
    
    FBSDKShareButton *button = [[FBSDKShareButton alloc] init];
    button.shareContent = content;  
    [self.view addSubview:button];