IOS高级错误’保留’被退回

我试过搜索但找不到答案。 我写了一个应用程序,我正在尝试分享内容到Facebook。 基本上我想分享一个URL,也许是一个引用或标题。

我一直收到一个名为’reserved’的错误,但我不确定它是什么意思或如何修复它。 任何帮助都会很棒!

func fbClick() { let content = LinkShareContent(url: URL(string: "www.google.com")!) showShareDialog(content, mode: .native) } func showShareDialog (_ 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) } } 

弄清楚了。

这条线……

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

应该是这样的……

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

或者像这样

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

有相同的reserved错误但使用VideoShareContent 。 花了5个小时找到问题,终于找到了。 真的希望有人发现这也很有帮助。

解决方案 :当您从UIImagePickerController委托方法的info param检索video的url ,请确保使用"UIImagePickerControllerReferenceURL"键。

例:

 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) } } } 

附加信息 :最初我没有使用这个键“UIImagePickerControllerReferenceURL”。 原因:它已被弃用 。 根据Apple的说法,你应该使用UIImagePickerControllerPHAsset代替。 但是那里的url也会返回reserved错误。 另一个尝试是使用键"UIImagePickerControllerMediaURL" ,但它也没有成功。