2
應用支持
的Alamofire自述表明您可以下載並保存這樣的文件:下載圖像使用Alamofire並保存到Mac上
let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
...但我想改變它的保存位置。如何在Mac OS X上將.DocumentDirectory
更改爲我應用的Application Support
路徑?
我可以生成我的應用程序的本地NSURL
路徑是這樣的:
let path = NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)[0] as NSURL
let newPath = path.URLByAppendingPathComponent("MyApp/user-profile.png")
我如何與Alamofire的suggestedDownloadDestination
使用這個不清楚。
任何想法?
啊,輝煌!非常感謝您的幫助。雖然我不得不刪除'destination:',因爲Xcode拋出了一個無關參數的警告: 'Alamofire.download(.GET,imgPath,{_ in newPath})' – 2015-02-08 07:23:42
啊是的。回答編輯。很高興它的工作。 – 2015-02-08 07:26:49