FBSDKShareContent分享本地图片

问题描述:

试图通过FBSDKShareLinkContent共享本地图片,但没有成功。FBSDKShareContent分享本地图片

我的示例代码:

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() 

以共享图片,你需要使用FBSDKSharePhotoContent。检查目标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

+0

我理解,但希望使用本地图片分享,而不是总是从网上下载 – Anton

+0

你上面的代码是共享的URL,在你不能给本地文件路径。 – Venkat