2017-08-24 15 views
1

以下のコードでバックグラウンドで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") 
    } 

} 

答えて

4

これを試してください: -

@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

関連する問題