我试图使用urlSession
. 但是当下载完成时,出现了一个意外的文件,名为CFNetworkDownload_gn6wzc.tmp
然后我无法使用该文件uidocumentinteractioncontroller.
是什么打开该文件?如何解决这个问题。谢谢回复。
这是消息
Your location is file:///Users/pisal/Library/Developer/CoreSimulator/Devices/26089E37-D4EA-49E5-8D45-BB7D9C52087D/data/Containers/Data/Application/767E966E-5954-41BA-B003-90E2D27C5558/Library/Caches/com.apple.nsurlsessiond/Downloads/com.SamboVisal.downloadTask/CFNetworkDownload_gn6wzc.tmp
这是我的示例代码:我通过这种方法发送链接
@IBAction func startDownload(_ sender: Any) {
let url = URL(string: "http://www.tutorialspoint.com/swift/swift_tutorial.pdf")!
let task = DownloadManager.shared.activate().downloadTask(with: url)
task.resume()
}
然后下载完成后:
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
debugPrint("Download finished: \(location)")
debugPrint("download task : \(downloadTask)")
ViewController().documentInteraction(location: location)
}
当我试图打开uidocumentinteractioncontroller
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
let destinationPath = documentDirectoryPath.appendingPathComponent("swift.pdf")
let destinationUrl = URL(fileURLWithPath: destinationPath)
do{
try FileManager.default.copyItem(at: locat, to: destinationUrl)
}
catch {
print("error copying file: \(error.localizedDescription)")
}
documentInteractionController.url = destinationUrl
if !documentInteractionController.presentOpenInMenu(from: openButton.bounds, in: view, animated: true) {
print("You don't have an app installed that can handle pdf files.")
}