Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post image on facebook using FBSDK 4.x for iOS

For the new Facebook SDK 4.x (4.1) for iOS had new changes with the frameworks . It includes 3 different framework as like

  • Core
  • Sharing
  • Login.

To share any image I used FBSDKSharePhoto Class. But it has method

[FBSDKSharePhoto photoWithImage:(*UIImage) userGenerated:(BOOL)]

I want to add caption with the image as string and text. can Anyone help me for this so I can post caption with the image using FB's new sdk.

Thanks in Advance.

like image 345
Esha Avatar asked May 19 '15 06:05

Esha


2 Answers

As @NANNAV posted it will work, but if you want to share silently with out any FB Dialog screen then use "shareWithContent" as below, but you need to submit your Facebook app for review.

Code in Obj-c

FBSDKSharePhoto *sharePhoto = [[FBSDKSharePhoto alloc] init];
sharePhoto.caption = @"Test Caption";
sharePhoto.image = [UIImage imageNamed:@"BGI.jpg"];

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

[FBSDKShareAPI shareWithContent:content delegate:self];

Code in Swift

var sharePhoto = FBSDKSharePhoto()
sharePhoto.caption = "Test"
sharePhoto.image = UIImage(named: "BGI.jpg")

var content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]

FBSDKShareAPI.shareWithContent(content, delegate: self)
like image 63
Shiva Kumar Avatar answered Oct 27 '22 20:10

Shiva Kumar


Assign your Caption String to caption Key value

@property (nonatomic, copy) NSString *caption;

Try This :

 FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
      photo.image = image;
      photo.userGenerated = YES;
    photo.caption = @"Add Your caption";
      FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
      content.photos = @[photo];
    [FBSDKShareDialog showFromViewController:self
                                 withContent:content
                                    delegate:nil];
like image 42
NANNAV Avatar answered Oct 27 '22 20:10

NANNAV