IOS FacebookShare Error 'reserved' being r

2019-07-17 06:08发布

问题:

I've tried searching but could not find an answer. I have written an app and I am trying to share content to facebook. Basically I would like to share a URL and maybe a quote or title.

I keep getting an error called 'reserved' but I am not sure what it means or how to fix it. Any help would be great!

func fbClick() {

    let content = LinkShareContent(url: URL(string: "www.google.com")!)
    showShareDialog(content, mode: .native)

}

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

    do {
        try dialog.show()
    } catch (let error) {
        self.view.makeToast("Invalid share content. Failed to present share dialog with error \(error)", duration: 3.0, position: .top)
    }
}

回答1:

Figured it out.

This line...

let content = LinkShareContent(url: URL(string: "www.google.com")!)

Should have been like this...

let content = LinkShareContent(url: NSURL(string: "https://www.google.com")! as URL)

or like this

let content = LinkShareContent(url: NSURL(string: "https://www.google.com")! as URL, quote: quote)


回答2:

Had the same reserved error but while using VideoShareContent. Spent 5 hours to find the issue and finally found. Really hope someone finds this helpful too.

Solution: when you are retrieving the url of your video from info param from the UIImagePickerController delegate method make sure you use the key "UIImagePickerControllerReferenceURL".

Example:

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)
        do {
            try ShareDialog.show(from: self, content: content)
        } catch {
            print(error)
        }
    }
}

Additional info: initially I did not use this key "UIImagePickerControllerReferenceURL". Why: it's deprecated. According to Apple, you should use UIImagePickerControllerPHAsset instead. But the url from there also returns reserved error. Another try was to use key "UIImagePickerControllerMediaURL", but it also didn't succeed.