I want to share a video on facebook by taking it from the bundle. I use this facebook SDK for swift, but I can not share the video with ShareDialog.
This is my code:
class ViewController: UIViewController, LoginButtonDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
let bundlePath = Bundle.main.url(forResource: "fish3", withExtension: "mp4")?.path
@IBOutlet weak var loginView: UIView!
let actionCanc = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
override func viewDidLoad() {
super.viewDidLoad()
//Login Button
let loginButton = LoginButton(publishPermissions: [.publishActions])
loginButton.delegate = self
loginButton.center = loginView.center
loginView.addSubview(loginButton)
}
//---------------------------------------
//MARK: Login via LoginButton
//---------------------------------------
func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
print("Did complete login via LoginButton with result \(result)")
}
func loginButtonDidLogOut(_ loginButton: LoginButton) {
print("Did logout via LoginButton")
}
//---------------------------------------
//MARK: Share Dialog
//---------------------------------------
func showShareDialog<C: ContentProtocol>(_ content: C, mode: ShareDialogMode){
let shareDialog = ShareDialog(content: content)
shareDialog.presentingViewController = self
shareDialog.mode = mode
do{
try shareDialog.show()
} catch(let error){
let alertController = UIAlertController(title: "Invalid share content", message: "Failed to present share dialog with error \(error)", preferredStyle: .alert)
alertController.addAction(actionCanc)
present(alertController, animated: true, completion: nil)
}
}
//---------------------------------------
//MARK: Video Content
//---------------------------------------
//Share from Bundle
@IBAction func shareVideoFromBundle() {
let videoUrl = URL(fileURLWithPath: bundlePath!)
let video = Video(url: videoUrl)
print("FILE VIDEO")
print(video)
let content = VideoShareContent(video: video)
showShareDialog(content, mode: .automatic)
}
}
When I try to share the video, prints the error in the catch: "Invalid share content"
can someone help me?