Facebook分享本地图像而不是NSURL for Image

时间:2015-02-11 23:59:42

标签: objective-c facebook facebook-graph-api swift

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!")
            }
        })
    }
}

0 个答案:

没有答案