Facebook分享publish_actions
使用NSURL检索图像以进行共享。是否有一种解决方法使用swift将UIImage而不是NSURL传递给facebook?
UIImage:fbShareImage
应该用作图像而不是NSURL。
func shareFB() {
var indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(reportBtnPos!)!
var params = FBLinkShareParams()
params.link = NSURL(string: "http://www.stackoverflow.com")
params.linkDescription = self.photoNames[indexPath.row]
let indexCell = tableView.cellForRowAtIndexPath(indexPath) as FeedCell!;
var fbShareImage = indexCell.mainRestaurantImageView!.image
println("params.link:\(params.link)")
if fbShareImage == nil || "title" == ""
{
params.picture = nil
}
else{
params.picture = fbShareImage
}
// If the Facebook app is installed and we can present the share dialog
if FBDialogs.canPresentShareDialogWithParams(params) == true
{
FBDialogs.presentShareDialogWithParams(params, clientState: nil, handler: {
call, results, error in
if error != nil{
println("Failed!")
}
else{
println("Success!")
}
})
}
else
{
// FALLBACK: publish just a link using the Feed dialog
// Put together the dialog parameters
var paramsDic = [
"description": params.linkDescription,
"link": "URL here",
]
if params.picture != nil
{
paramsDic = [
"description": params.linkDescription,
"link": "link here",
"picture": "IMAGE URL"]
}
// show the feed dialog
FBWebDialogs.presentFeedDialogModallyWithSession(nil, parameters: paramsDic, handler: {
result, resultURL, error in
println("result==>>>\(result.hashValue)")
if result.hashValue == 1
{
println("Failed!")
}
else
if result.hashValue == 0
{
println("Success!")
}
})
}
}