GithubHelp home page GithubHelp logo

rrdownloadfile's Introduction

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
}

rrdownloadfile's People

Contributors

remirobert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.