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?

itemprop = "text">

issue path url is the property calculated after

.path ), you will see that your URL is not valid. This is because you are using 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")}  

or, even better, the path completely bypass, and use 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")}  

or Swift in 3:

  var url URL: try {return! In FileManagerkdefaultkurlForDirectory (KdocumentDirectory: KuserDomainMask, AppropriateFor: Create zero, incorrect) .appendingPathComponent ( "test.pdf")}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -