FBSDKShareContent共享本地图像

时间:2015-10-06 10:58:25

标签: ios facebook swift facebook-share fbsdk

尝试通过FBSDKShareLinkContent共享本地图像,但没有成功。

我的示例代码是:

 let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
    content.contentTitle = "test share"
    content.contentURL = NSURL(string: "http://example.com")
    let path = NSBundle.mainBundle().pathForResource("testImage", ofType: "png")
    content.imageURL = NSURL(string: path!)
    let shareDialog = FBSDKShareDialog()
    shareDialog.mode = FBSDKShareDialogMode.Native
    shareDialog.shareContent = content
    shareDialog.fromViewController = self
    shareDialog.show()

1 个答案:

答案 0 :(得分:0)

要共享图片,您需要使用FBSDKSharePhotoContent。检查Objective C中的以下代码

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  UIImage *image = info[UIImagePickerControllerOriginalImage];

  FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
  photo.image = image;
  photo.userGenerated = YES;
  FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
  content.photos = @[photo];
  ...
}

参考:https://developers.facebook.com/docs/sharing/ios