使用FBSDK 4.x for iOS在Facebook上发布图像

Esh*_*sha 6 xcode facebook ios facebook-sdk-4.0

对于新Facebook SDK 4.x (4.1) for iOS的框架有新的变化.它包括3个不同的框架

  • 核心
  • 分享
  • 登录.

要分享我使用FBSDKSharePhotoClass的任何图像.但它有方法

[FBSDKSharePhoto photoWithImage:(*UIImage) userGenerated:(BOOL)]
Run Code Online (Sandbox Code Playgroud)

我想添加标题作为字符串和文本的图像.任何人都可以帮助我,所以我可以使用FB的新sdk发布图像标题.

提前致谢.

Shi*_*mar 7

正如@NANNAV发布它会起作用,但是如果你想在任何FB Dialog屏幕上静默分享,那么使用如下所示的"shareWithContent",但你需要提交你的Facebook应用程序进行审核.

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];
Run Code Online (Sandbox Code Playgroud)

Swift中的代码

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

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

FBSDKShareAPI.shareWithContent(content, delegate: self)
Run Code Online (Sandbox Code Playgroud)


NAN*_*NAV 5

将标题字符串分配给标题键值

@property(非原子,复制)NSString*标题;

试试这个 :

 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];
Run Code Online (Sandbox Code Playgroud)

  • 它显示对话框和添加在Facebook上发布的文本后.但添加的标题没有显示在帖子上....请检查 (9认同)