Skip to content

Commit

Permalink
release 2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Danie1s committed Jan 10, 2020
1 parent c0edaf6 commit 675822b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/Extensions/UIDevice+Free.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// THE SOFTWARE.
//

import Foundation
import UIKit


extension UIDevice: TiercelCompatible {}
Expand Down
22 changes: 13 additions & 9 deletions Sources/General/DownloadTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DownloadTask: Task<DownloadTask> {
private enum CodingKeys: CodingKey {
case resumeData
}

fileprivate var acceptableStatusCodes: Range<Int> { return 200..<300 }

internal var sessionTask: URLSessionDownloadTask? {
willSet {
Expand Down Expand Up @@ -362,10 +364,8 @@ extension DownloadTask {
validateFile()
}

private func determineStatus(error: Error?, statusCode: Int) {
if statusCode != 200 {
status = .failed
}
private func determineStatus(with error: Error?) {
var tempStatus = status

if let error = error {
self.error = error
Expand All @@ -375,12 +375,15 @@ extension DownloadTask {
cache.storeTmpFile(self)
}
if let _ = (error as NSError).userInfo[NSURLErrorBackgroundTaskCancelledReasonKey] as? Int {
status = .suspended
tempStatus = .suspended
}
if let urlError = error as? URLError, urlError.code != URLError.cancelled {
status = .failed
tempStatus = .failed
}
} else {
tempStatus = .failed
}
status = tempStatus

switch status {
case .suspended:
Expand Down Expand Up @@ -499,7 +502,7 @@ extension DownloadTask {

internal func didFinishDownloading(task: URLSessionDownloadTask, to location: URL) {
guard let statusCode = (task.response as? HTTPURLResponse)?.statusCode,
statusCode == 200
acceptableStatusCodes.contains(statusCode)
else { return }
self.tmpFileURL = location
cache.storeFile(self)
Expand All @@ -519,11 +522,12 @@ extension DownloadTask {


let statusCode = (task.response as? HTTPURLResponse)?.statusCode ?? -1
let isAcceptable = acceptableStatusCodes.contains(statusCode)

if error == nil && statusCode == 200 {
if error == nil && isAcceptable {
succeeded()
} else {
determineStatus(error: error, statusCode: statusCode)
determineStatus(with: error)
}

manager?.determineStatus()
Expand Down
2 changes: 1 addition & 1 deletion Tiercel.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'Tiercel'
s.version = '2.4.0'
s.version = '2.4.1'
s.swift_version = '5.0'
s.summary = 'Tiercel is a lightweight, pure-Swift download framework.'

Expand Down
4 changes: 2 additions & 2 deletions Tiercel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.4.0;
MARKETING_VERSION = 2.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.Daniels.Tiercel;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -575,7 +575,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.4.0;
MARKETING_VERSION = 2.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.Daniels.Tiercel;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down

0 comments on commit 675822b

Please sign in to comment.