Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 浏览文件并希望上载到服务器上_Ios_Swift_Uidocumentbrowserviewcontroller - Fatal编程技术网

Ios 浏览文件并希望上载到服务器上

Ios 浏览文件并希望上载到服务器上,ios,swift,uidocumentbrowserviewcontroller,Ios,Swift,Uidocumentbrowserviewcontroller,我正在使用UIDocumentBrowserViewController浏览文件,并从UIDocumentBrowserViewControllerDelegate方法获取所选文件的URL func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) { guard let fileUrl = documentURLs.fir

我正在使用UIDocumentBrowserViewController浏览文件,并从UIDocumentBrowserViewControllerDelegate方法获取所选文件的URL

 func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) {
        guard let fileUrl = documentURLs.first else { return }
         do {
              let fileData = try Data(contentsOf: fileUrl)
          } catch {
              print(error.localizedDescription)
          }
 }

现在我必须把这个文件上传到我们的应用服务器上,所以我试图把它转换成数据,但它没有转换。出现错误“文件名无法打开,因为没有这样的文件”。

我使用的是UIDocumentBrowserViewController,但在我尝试导入文档时它不起作用。总是会遇到问题,所以我使用UIDocumentPickerViewController,它对我来说可以正常工作。

它能让你放心吗?它会打印什么吗?@PhillipMills是的,我可以获取URL,但无法将其转换为数据