An open API service indexing awesome lists of open source software.

https://github.com/remirobert/rrdownloadfile

Download file from URL for iOS 7.X
https://github.com/remirobert/rrdownloadfile

Last synced: about 1 year ago
JSON representation

Download file from URL for iOS 7.X

Awesome Lists containing this project

README

          

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:

```swift
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

```swift
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

```swift
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.

```swift
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
}

```