更新到iOS 11.1后,Alamofire 4.5.1失败

问题描述 投票:1回答:1

更新到iOS 11.1后,.sqlite下载失败。我已经确认我有最新的Alamofire库(4.5.1),我已经卸载并重新安装使用pod。我已经清理了项目并试图调试它但我找不到问题,只是我注意到temporaryURL是零。

我的代码:

        let parameters: Parameters = [:]

        var filePath: URL?

        let destination: (URL, HTTPURLResponse) -> (URL, DownloadRequest.DownloadOptions) = {
            (temporaryURL, response) in

            if let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first, let suggestedFilename = response.suggestedFilename {
                filePath = directoryURL.appendingPathComponent("\(suggestedFilename)")
                return (filePath!, [.removePreviousFile, .createIntermediateDirectories])
            }
            return (temporaryURL, [.removePreviousFile, .createIntermediateDirectories])
        }

        Alamofire.download("https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3", method: .get, parameters: parameters, encoding: JSONEncoding.default, to: destination)
            .downloadProgress { progress in
                DispatchQueue.main.async
                {
                    /.../                        
                }
            }
            .validate { request, response, temporaryURL, destinationURL in
                /.../
                return .success
            }
            .response { response in

                debugPrint(response)
                print("Descarga finalizada");
                /.../
            }

.downloadProgress工作正常。但当它达到100%时,该过程不会继续,并且由于等待时间耗尽而等待它结束(-1001)

控制台输出与调试:

2017-11-07 12:04:28.422333+0100 Target[673:215766] Task <26F62B6A-FEB4-4908-92C9-D3F9C9886C81>.<4> finished with error - code: -1001

Alamofire.DefaultDownloadResponse(request: Optional(https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3), response: Optional(<NSHTTPURLResponse: 0x1c0235220> { URL: https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3 } { Status Code: 200, Headers {
    "Accept-Ranges" =     (
        bytes
    );
    "Content-Length" =     (
        28086272
    );
    "Content-Type" =     (
        "application/octet-stream"
    );
    Date =     (
        "Tue, 07 Nov 2017 11:02:52 GMT"
    );
    Etag =     (
        "\"xxxxxxxxxxxxxxxxx\""
    );
    "Last-Modified" =     (
        "Tue, 07 Nov 2017 01:44:00 GMT"
    );
    Server =     (
        AmazonS3
    );
    "x-amz-id-12" =     (
        "LiCdsdasdasfsdfdsffgsfdsw3o+npOhfUVLdZ/KlTWgLXdPNPU8iYnZIkeGoRvBkLbKwFFY="
    );
    "x-amz-request-id" =     (
        9CD8D133234DB
    );
} }), temporaryURL: nil, destinationURL: nil, resumeData: Optional(7043 bytes), error: Optional(Error Domain=NSURLErrorDomain Code=-1001 "Se ha agotado el tiempo de espera." UserInfo={_kCFStreamErrorCodeKey=-2102, NSURLSessionDownloadTaskResumeData=<CFData 0x1c0649390 [0x1b1491310]>{length = 7043, capacity = 16384, bytes = 0x3c3f786d6c2076657273696f6e3d2231 ... 2f706c6973743e0a}, NSUnderlyingError=0x1c0649e10 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSLocalizedDescription=Se ha agotado el tiempo de espera., NSErrorFailingURLStringKey=https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3, NSErrorFailingURLKey=https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3, _kCFStreamErrorDomainKey=4}), timeline: Timeline: { "Request Start Time": 531745370.759, "Initial Response Time": 531745371.441, "Request Completed Time": 531745468.447, "Serialization Completed Time": 531745468.450, "Latency": 0.682 secs, "Request Duration": 97.688 secs, "Serialization Duration": 0.003 secs, "Total Duration": 97.691 secs }, _metrics: Optional((Task Interval) <_NSConcreteDateInterval: 0x1c003f5c0> (Start Date) 2017-11-07 11:02:50 +0000 + (Duration) 97.667806 seconds = (End Date) 2017-11-07 11:04:28 +0000
(Redirect Count) 0
(Transaction Metrics) (Request) <NSURLRequest: 0x1c00019d0> { URL: https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3, Method GET, Headers {
    Accept =     (
        "*/*"
    );
    "Accept-Encoding" =     (
        "gzip;q=1.0, compress;q=0.5"
    );
    "Accept-Language" =     (
        "es-ES;q=1.0, fr-ES;q=0.9, en-ES;q=0.8"
    );
    Connection =     (
        "keep-alive"
    );
    "Content-Type" =     (
        "application/json"
    );
    Host =     (
        "s3-eu-west-1.amazonaws.com"
    );
    "User-Agent" =     (
        "Targer/1.7 (com.xxxxx.xxxxx; build:156; iOS 11.1.0) Alamofire/4.5.1"
    );
} }
(Response) <NSHTTPURLResponse: 0x1c0030ae0> { URL: https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3 } { Status Code: 200, Headers {
    "Accept-Ranges" =     (
        bytes
    );
    "Content-Length" =     (
        28086272
    );
    "Content-Type" =     (
        "application/octet-stream"
    );
    Date =     (
        "Tue, 07 Nov 2017 11:02:52 GMT"
    );
    Etag =     (
        "\"6c9de7be53a1cdfser61ca7fa1a4\""
    );
    "Last-Modified" =     (
        "Tue, 07 Nov 2017 01:44:00 GMT"
    );
    Server =     (
        AmazonS3
    );
    "x-amz-id-2" =     (
        "LiCk24ajVvge+qcds5hgfbgdfxgnhFOhfUVLdZ/KlTWgLXdPNPU8iYnZIkeGoRvBkLbKwFFY="
    );
    "x-amz-request-id" =     (
        9CD8SDHD7B81DB
    );
} }
(Fetch Start) 2017-11-07 11:02:50 +0000
(Domain Lookup Start) 2017-11-07 11:02:50 +0000
(Domain Lookup End) 2017-11-07 11:02:50 +0000
(Connect Start) 2017-11-07 11:02:50 +0000
(Secure Connection Start) 2017-11-07 11:02:50 +0000
(Secure Connection End) 2017-11-07 11:02:51 +0000
(Connect End) 2017-11-07 11:02:51 +0000
(Request Start) 2017-11-07 11:02:51 +0000
(Request End) 2017-11-07 11:02:51 +0000
(Response Start) 2017-11-07 11:02:51 +0000
(Response End) 2017-11-07 11:03:27 +0000
(Protocol Name) http/1.1
(Proxy Connection) NO
(Reused Connection) NO
(Fetch Type) Network Load

))

Descarga finalizada

但是,该文件已下载到路径:

我使用更简单的版本更改了文件的目标:

let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)

但问题是一样的。

iOS 10.3完美运行。

感谢任何帮助,谢谢。

download alamofire swift4
1个回答
0
投票

我通过从以下位置删除其他参数来解决它:

Alamofire.download("https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3", method: .get, parameters: parameters, encoding: JSONEncoding.default, to: destination)

至:

Alamofire.download("https://s3-eu-west-1.amazonaws.com/xxx/xxx/xxx.sqlite3",  to: destination)

我不确定什么是错的,但这就是它的工作原理

© www.soinside.com 2019 - 2024. All rights reserved.