与标题共享照片到背景中的Facebook

问题描述:

我成功地发布了一个图像到Facebook的背景下面的代码,但不知何故不知道如何包含字幕。我已阅读官方文件,但仍无法找到任何文件。请帮忙。提前致谢。与标题共享照片到背景中的Facebook

import UIKit 
import FBSDKLoginKit 
import FBSDKShareKit 


class ViewController: UIViewController, FBSDKLoginButtonDelegate, FBSDKSharingDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     let loginButton = FBSDKLoginButton() 
     loginButton.center = view.center 
     view.addSubview(loginButton) 
     loginButton.delegate = self 
    } 

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { 
     if (FBSDKAccessToken.current() != nil) { FBSDKGraphRequest(graphPath: "me", parameters: nil).start(completionHandler: 
      {(connection, result, error) in 
       if error == nil { 
        print("fetch user \(result)") 
       } 
      }) 
     } 
    } 

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) { 
     print("you logout") 
    } 


    @IBAction func postImage(_ sender: Any) { 
     let img = UIImage(named: "image") 
     let content = FBSDKSharePhotoContent() 
     content.photos = [FBSDKSharePhoto(image: img, userGenerated: true)] 
     FBSDKShareAPI.share(with: content, delegate: self) 
    } 

    func sharerDidCancel(_ sharer: FBSDKSharing!) { 
     print("sharerDidCancel") 
    } 

    func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) { 
     print("didFail") 
    } 

    func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) { 
     print("didCompleteWithResult") 
    } 

} 

试试这个: -

@IBAction func postImage(_ sender: Any) { 
    let img = UIImage(named: "image") 
    let photo = FBSDKSharePhoto() 
    photo.image = img 
    photo.caption = "Test Caption" 
    photo.isUserGenerated = true 
    let content = FBSDKSharePhotoContent() 
    content.photos = [photo] 
    FBSDKShareAPI.share(with: content, delegate: self) 
} 
+0

它的作品!非常感谢! :)))) – mclovin

+0

欢迎 mclovin – Pushpendra

+0

这太酷了,救了我的命 – Ali