Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post Video to Facebook with swift SDK

I have been trying to figure this out all day and yesterday night, but no luck. I can confirm that the LinkShareContent works but when I try to share a video file. It gives me an error code "reserved" but nothing else.

This is the code for the link

var content = LinkShareContent(url: URL(string: "https://google.com")!)
showShareDialog(content)

and this is the code for the video that does not work at all.

 let video = Video(url: url)
 var content = VideoShareContent(video: video, previewPhoto: Photo(image: inProgressItem.firstImage, userGenerated: true))
 showShareDialog(content)

This will show the share Sheet on the controller

  Func showShareDialog<C: ContentProtocol>(_ content: C, mode: ShareDialogMode = .shareSheet) {
        let dialog = ShareDialog(content: content)
        dialog.presentingViewController = self
        dialog.mode = mode

        do{
            try dialog.show()
        }
        catch (let error){
            print(error)
        }
    }

I have confirmed that the video is on the local path and I'm testing the app on iPhone 8 11.1.2

like image 448
Jean Pierre Avatar asked Jan 24 '18 21:01

Jean Pierre


1 Answers

Had exactly the same issue. It was working for LinkShareContent but didn't work for VideoShareContent.

The solution: Make sure you are getting the right URL for the video. The right one is the URL for key "UIImagePickerControllerReferenceURL" from info dictionary that comes from UIImagePickerController delegate method.

Working Code:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
    picker.dismiss(animated: true)
    if let videoURL = info["UIImagePickerControllerReferenceURL"] as? URL {
        let video = Video(url: videoURL)
        let content = VideoShareContent(video: video)
        let dialog = ShareDialog(content: content)
        dialog.failsOnInvalidData = true
        dialog.mode = .native
        dialog.presentingViewController = self
        do {
            try dialog.show()
        } catch {
           print(error)
        }
    }
}

Extra info: initially I did not use this key "UIImagePickerControllerReferenceURL" cuz it's deprecated. Apple advises using UIImagePickerControllerPHAsset instead. But the URL from there also returns reserved error. Another try was to use key "UIImagePickerControllerMediaURL", but it also didn't succeed.

like image 125
Tung Fam Avatar answered Oct 13 '22 20:10

Tung Fam