Skip to content

remirobert/RRDownloadFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RRDownloadFile

Allows you to download files from url and store them in the device disk. Available only for iOS 7.0+. You can pause, resume or cancel a download, when and where you want. It works also in background task, so you can download file when the application is in background or close by the user. RRDownloadFile uses NSURLSession for make the download.

Usage

Simple Download:
let url = NSURL(string: "https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/NetworkingOverview.pdf")
        
RRDownloadFile.download("network.pdf", downloadSource: url!,
progressBlockCompletion: nil) { (error, fileDestination) -> () in
  if error == nil {
    println("file downloaded :\(fileDestination)")
  }
}

Trace the download progress

RRDownloadFile.download("network.pdf", downloadSource: url!, progressBlockCompletion: { (bytesWritten, bytesExpectedToWrite) -> () in
  println("progress :\(bytesWritten) / \(bytesExpectedToWrite)")
}) { (error, fileDestination) -> () in
  if error == nil {
    println("file downloaded :\(fileDestination)")
  }
}

Pause, resume, and cancel a download

let downloadTask = RRDownloadFile.download("network.pdf", downloadSource: url!, progressBlockCompletion: nil) { (error, fileDestination) -> () in
  if error == nil {
    println("file downloaded :\(fileDestination)")
  }
}
        
RRDownloadFile.pauseDownload(downloadTask: downloadTask)
RRDownloadFile.resumeDownload(downloadTask: downloadTask)
RRDownloadFile.cancelDownload(downloadTask: downloadTask)

You can change the destination of a download by passing the url in parameter. If the path doesn't exsit it will be created.

let customDestinationPath = NSURL(string: "Download/pdf")

RRDownloadFile.download("network.pdf", downloadSource: url!, pathDestination: customDestinationPath!, progressBlockCompletion: nil) { (error, fileDestination) -> () in
  //The file will be saved in DocumentDirectory/Download/pdf/network.pdf
}

About

Download file from URL for iOS 7.X

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages