4Manuals

  • PDF Cloud HOME

PDFkit无法快速选择本地文件URL Download

    API集成以验证ResearchKit ORKFormItem 转换后的SELECT下拉列表(以ul为单位)不会显示在SAFARI 如何在Swift中将数组的每个元素与下一个数组的每个元素相乘? 从网络加载图像时,“接收到完整的报头之前关闭连接 UITableView动画大小调整问题 ios的到期通知 如何快速设置基本身份验证 如何在Swift4 +中将数组数组作为标准POST方法发送 重新创建当前在IOS 13上的Apple的UI强度滑块 在窗口内创建菜单

我已经使用Alamofire实现了下载文件功能。文件下载成功,但是当我尝试在本地读取文件时,它总是给我Fatal error: Unexpectedly found nil while unwrapping an Optional value。如果我将粘贴本地文件链接复制到浏览器,则会打开文件或在Finder中打开文件。

在线错误: pdfView.document = PDFDocument(url: fileURL!)

响应本地文件位置:

/Users/abc/Library/Developer/CoreSimulator/Devices/4B6C2727-46AB-4797-8CBB-D5A897867013/data/Containers/Data/Application/C782E91D-9E63-4D1D-BBB3-2CD0414E6EA6/Documents/3602319458509320922.pdf

代码:

let fileType = (URL != nil) ? ".pdf" : ".png"

        DataProvider.main.downloadFile(url: String(describing: self.URL!), filetype: fileType, callback: { success, response in

            if !success || response == nil {
                return false
            }
            if((response as! String).hasSuffix("pdf")){

                print(response)
                let fileURL = Bundle.main.url(forResource: response as? String, withExtension: "pdf")
                pdfView.document = PDFDocument(url: fileURL!)


            }else if (FileManager.default.fileExists(atPath: (response as! String).removingPercentEncoding!) ){

                let fileURL = Bundle.main.url(forResource: response as? String, withExtension: "pdf")
                pdfView.document = PDFDocument(url: fileURL!)

            }
            return true
        })

0 个答案:

没有答案



Similar searches
    从api获取数据后,在React中显示嵌套对象? Instagram用户的联系电子邮件? 将VBA日期函数转换为SQL 如何正则表达式替换所有特殊字符(除非两个特殊字符)? Samsung RS2534VQ Refrigerator User Manual