2015-10-06 109 views
1

試圖通過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() 

回答

0

以共享圖片,你需要使用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