FBSDKShareContent 分享本地图片
Posted
技术标签:
【中文标题】FBSDKShareContent 分享本地图片【英文标题】:FBSDKShareContent share local image 【发布时间】:2015-10-06 10:58:25 【问题描述】:尝试通过 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】:要分享图片,您需要使用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
【讨论】:
我明白了,但是想用本地图片分享而不是总是从网上下载 你上面的代码是分享网址,不能给出本地文件路径。以上是关于FBSDKShareContent 分享本地图片的主要内容,如果未能解决你的问题,请参考以下文章
Android分享笔记 Android的webview加载本地html本apk内html和远程URL