我正在尝试从 Internet 下载文件并将其放在应用程序支持目录下的应用程序名称目录中,但我不断收到
Assertion failed: ([path isAbsolutePath]), function -[NSURLDownload setDestination:allowOverwrite:], file /SourceCache/CFNetwork/CFNetwork-720.5.7/Foundation/NSURLDownload.mm, line 370.
这是我写的代码:
var imageRequest = NSURLRequest(URL: self.source)
var imageDownload = NSURLDownload(request: imageRequest, delegate:self)
var error: NSError? = NSError()
/* does path exist */
let directoryPath = self.destination.stringByDeletingLastPathComponent
let fileMgr = NSFileManager();
fileMgr.createDirectoryAtPath(directoryPath, withIntermediateDirectories: true, attributes: nil, error: &error)
imageDownload.setDestination(self.destination, allowOverwrite: true);
当我单步执行代码时,一切看起来都是正确的。self.source 是 (https://remoteDomain.com/img/downloadimage.jpg) 一个 NSURL
self.destination 是我系统中的完整路径(文件:/Users/ryan/Library/Application%20Support/AppName/downloadimage.jpg)
有任何想法吗?