Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional data added to handle custom functionalities #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>MZDownloadManager-Example.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ extension MZAvailableDownloadsViewController {
//Use it download at default path i.e document directory
// mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL as String)

mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL as String, destinationPath: myDownloadPath)
// mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL as String, destinationPath: myDownloadPath)

mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL as String, destinationPath: myDownloadPath, additionalData: [:])

availableDownloadsArray.remove(at: (indexPath as NSIndexPath).row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.right)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions MZDownloadManager/Classes/MZDownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l > r
default:
return rhs < lhs
}
switch (lhs, rhs) {
case let (l?, r?):
return l > r
default:
return rhs < lhs
}
}


Expand Down Expand Up @@ -350,7 +350,7 @@ extension MZDownloadManager: URLSessionDownloadDelegate {

extension MZDownloadManager {

@objc public func addDownloadTask(_ fileName: String, request: URLRequest, destinationPath: String) {
@objc public func addDownloadTask(_ fileName: String, request: URLRequest, destinationPath: String, additionalData: [String: Any]) {

let url = request.url!
let fileURL = url.absoluteString
Expand All @@ -365,25 +365,26 @@ extension MZDownloadManager {
downloadModel.startTime = Date()
downloadModel.status = TaskStatus.downloading.description()
downloadModel.task = downloadTask
downloadModel.additionalData = additionalData

downloadingArray.append(downloadModel)
delegate?.downloadRequestStarted?(downloadModel, index: downloadingArray.count - 1)
}

@objc public func addDownloadTask(_ fileName: String, fileURL: String, destinationPath: String) {
@objc public func addDownloadTask(_ fileName: String, fileURL: String, destinationPath: String, additionalData: [String: Any]) {

let url = URL(string: fileURL)!
let request = URLRequest(url: url)
addDownloadTask(fileName, request: request, destinationPath: destinationPath)
addDownloadTask(fileName, request: request, destinationPath: destinationPath, additionalData: additionalData)

}

@objc public func addDownloadTask(_ fileName: String, fileURL: String) {
addDownloadTask(fileName, fileURL: fileURL, destinationPath: "")
addDownloadTask(fileName, fileURL: fileURL, destinationPath: "", additionalData: [:])
}

@objc public func addDownloadTask(_ fileName: String, request: URLRequest) {
addDownloadTask(fileName, request: request, destinationPath: "")
addDownloadTask(fileName, request: request, destinationPath: "", additionalData: [:])
}

@objc public func pauseDownloadTaskAtIndex(_ index: Int) {
Expand Down
3 changes: 3 additions & 0 deletions MZDownloadManager/Classes/MZDownloadModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ open class MZDownloadModel: NSObject {

open var startTime: Date?

open var additionalData: [String: Any]?

fileprivate(set) open var destinationPath: String = ""

fileprivate convenience init(fileName: String, fileURL: String) {
Expand All @@ -60,4 +62,5 @@ open class MZDownloadModel: NSObject {

self.destinationPath = destinationPath
}

}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pod "MZDownloadManager"

## Update

### New helper functions
New helper functions added to support downloading at custom path. Example project is also updated about the usage.

To download file at custom path you can use the following instance method of MZDownloadManager:
Expand All @@ -56,6 +57,22 @@ To download file at custom path you can use the following instance method of MZD

* If the above delegate method is not implemented then it will just called the failure method.


### Additional Data
New parameter added to store and pass the additional values of the downloaded files to perform custom functionalities

Example project is also updated about the usage.

```open var additionalData: [String: Any]?)```

#### New helper functions

New helper functions added to support downloading with additional data.

```public func addDownloadTask(_ fileName: String, fileURL: String, destinationPath: String, additionalData: [String: Any])```



> Important: This delegate method will be called on the session's queue.

## Author
Expand Down