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
- Host: GitHub
- URL: https://github.com/remirobert/rrdownloadfile
- Owner: remirobert
- License: mit
- Created: 2014-11-30T12:08:00.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-01T14:08:56.000Z (over 11 years ago)
- Last Synced: 2025-04-06T10:47:17.472Z (about 1 year ago)
- Language: Swift
- Size: 273 KB
- Stars: 6
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
}
```