【发布时间】:2016-09-04 10:23:41
【问题描述】:
我使用这种 Alamofire 方式下载外部 pdf 文件。
问题是,我想保留它以供下次用户打开应用程序使用。所以用户不需要再次下载pdf。
我用下面的方法下载
let destination =
Alamofire.Request.suggestedDownloadDestination(directory: .CachesDirectory,
domain: .UserDomainMask);
Alamofire.download(.GET, urlString, destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
}
.response { request, response, _, error in
print("Downloaded to \(destination(NSURL(string: "")!, response!))");
}
下载的文件路径是这样的。
file:///var/mobile/Containers/Data/Application/4957AD15-947A-47D6-A126-EA06A5BCB099/Library/Caches/RewardMe-Presentation-at-NVIDIA-Auditorium.pdf
如何在我的应用下次启动时保留该文件?
我在下次应用启动时将该路径保存到 NSUserDefaults 中,但该文件已经消失了。
【问题讨论】:
-
简单地将文件保存在 NSDocumentDirectory 或 NSBundle 中,然后从那里获取它
-
我如何做到这一点? @AbdulRehmanWarraich
标签: ios pdf alamofire nsurlsession afnetworking-2