Download file with AFNetworking in swift -
I want to download Firefox from URL, which is fast in fast networking, and showing download progress . I have this code, but it does not work:
function downloadPdf () {var request = NSURLRequest (url: NSURL (string: "http://www.sa.is/media /1039/example.pdf ")) Session = AFHTTessionManager () progress: NSProgress? Var downloadTask = session.downloadTaskWithRequest (request Progress: & amp; progress destination: {(file self.pathUrl, reaction)}, CompletionHandler: {response, Localfile, error println ( "feedback \ (response)")} ) downloadTask.resume ()} var pathUrl: NSURL {var path = NSSearchPathForDirectoriesInDomains (.DocumentDirectory, .UserDomainMask, true) [0] string var = NSURL (string: path.stringByAppendingPathComponent ( "file.pdf") as the URL) Println (url .path) return url}
What do I do wrong?
issue or, even better, the path completely bypass, and use or Swift in 3: path url
is the property calculated after NSURL (string)
, and for the file URL, you should use the NSURL (fileURLWithPath :)
. Thus:
var pathUrl: NSURL {to documentsFolder = NSSearchPathForDirectoriesInDomains (.DocumentDirectory, .UserDomainMask, really) first! Go documentsURL = NSURL (fileURLWithPath: documentsFolder) return documentsURL.URLByAppendingPathComponent ( "file.pdf")}
URLForDirectory < / Code> To get the
.documentdirectory
as the URL:
var guide URL: NSRL {Return attempt! NSFileManager.defaultManager () URLForDirectory. (.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: Create zero, incorrect) .URLByAppendingPathComponent ( "test.pdf")}
var url URL: try {return! In FileManagerkdefaultkurlForDirectory (KdocumentDirectory: KuserDomainMask, AppropriateFor: Create zero, incorrect) .appendingPathComponent ( "test.pdf")}
Comments
Post a Comment