Alamofire会话管理器随机崩溃,swift

Alamofire会话管理器随机崩溃,swift,swift,alamofire,xcode10.3,Swift,Alamofire,Xcode10.3,我在我的项目中使用Alamofire,但有时我在Alamofire实现文件中看到Alamofire会话管理器中出现一些不可复制的崩溃。因为它是不可复制的,所以在我的应用程序中会导致一些随机崩溃 经过大量调试,我发现一个日志,它可能是一个网络问题。如果有人能找到任何相同的东西,请帮助解决这个问题。提前谢谢 打开func makeRequest(管理器:SessionManager,方法:HTTPMethod,编码:ParameterEncoding,头:[String:String])->Data

我在我的项目中使用Alamofire,但有时我在Alamofire实现文件中看到Alamofire会话管理器中出现一些不可复制的崩溃。因为它是不可复制的,所以在我的应用程序中会导致一些随机崩溃

经过大量调试,我发现一个日志,它可能是一个网络问题。如果有人能找到任何相同的东西,请帮助解决这个问题。提前谢谢

打开func makeRequest(管理器:SessionManager,方法:HTTPMethod,编码:ParameterEncoding,头:[String:String])->DataRequest{

    return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers)
}

override open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) {
    let managerId:String = UUID().uuidString
    // Create a new manager for each request to customize its request header
    let manager = createSessionManager()
    managerStore[managerId] = manager

    let encoding:ParameterEncoding = isBody ? JSONDataEncoding() : URLEncoding()

    let xMethod = Alamofire.HTTPMethod(rawValue: method)
    let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL }
                                                       .map { $0.0 }
     // the status code
    if fileKeys.count > 0 {
        manager.upload(multipartFormData: { mpForm in
            for (k, v) in self.parameters! {
                switch v {
                case let fileURL as URL:
                    if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
                        mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType)
                    }
                    else {
                        mpForm.append(fileURL, withName: k)
                    }
                case let string as String:
                    mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k)
                case let number as NSNumber:
                    mpForm.append(number.stringValue.data(using: String.Encoding.utf8)!, withName: k)
                default:
                    fatalError("Unprocessable value \(v) with key \(k)")
                }
            }
            }, to: URLString, method: xMethod!, headers: nil, encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                if let onProgressReady = self.onProgressReady {
                    onProgressReady(upload.uploadProgress)
                }
                self.processRequest(request: upload, managerId, completion)
            case .failure(let encodingError):
                var statusCode = encodingResult
                if let error = encodingError as? AFError {
                  //  statusCode = error._code // statusCode private
                    switch error {
                    case .invalidURL(let url):
                        print("Invalid URL: \(url) - \(error.localizedDescription)")
                    case .parameterEncodingFailed(let reason):
                        print("Parameter encoding failed: \(error.localizedDescription)")
                        print("Failure Reason: \(reason)")
                    case .multipartEncodingFailed(let reason):
                        print("Multipart encoding failed: \(error.localizedDescription)")
                        print("Failure Reason: \(reason)")
                    case .responseValidationFailed(let reason):
                        print("Response validation failed: \(error.localizedDescription)")
                        print("Failure Reason: \(reason)")

                        switch reason {
                        case .dataFileNil, .dataFileReadFailed:
                            print("Downloaded file could not be read")
                        case .missingContentType(let acceptableContentTypes):
                            print("Content Type Missing: \(acceptableContentTypes)")
                        case .unacceptableContentType(let acceptableContentTypes, let responseContentType):
                            print("Response content type: \(responseContentType) was unacceptable: \(acceptableContentTypes)")
                        case .unacceptableStatusCode(let code):
                            print("Response status code was unacceptable: \(code)")
                           // statusCode = code
                        }
                    case .responseSerializationFailed(let reason):
                        print("Response serialization failed: \(error.localizedDescription)")
                        print("Failure Reason: \(reason)")
                        // statusCode = 3840 ???? maybe..
                    }

                    print("Underlying error: \(error.underlyingError)")
                } else if let error = encodingError as? AFError {
                    print("URLError occurred: \(error)")
                } else {
                    print("Unknown error: \(encodingError as? AFError)")
                }

                print(statusCode)
                completion(nil, ErrorResponse.error(415, nil, encodingError))
            }
        })
    } else {
        let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding, headers: headers)

        if let onProgressReady = self.onProgressReady {
            onProgressReady(request.progress)
        }
        processRequest(request: request, managerId, completion)
    }

}
returnmanager.request(URLString,method:method,parameters:parameters,encoding:encoding,headers:headers)
}
重写打开的func execute(\uCompletion:@escaping(\uResponse:response?,\uError:error?)->Void){
让managerId:String=UUID().uuistring
//为每个请求创建一个新的管理器,以自定义其请求头
让manager=createSessionManager()
managerStore[managerId]=管理器
let编码:ParameterEncoding=isBody?JSONDataEncoding():URLEncoding()
设xMethod=Alamofire.HTTPMethod(rawValue:method)
让fileKeys=parameters==nil?[]:parameters!。过滤器{$1是NSURL}
.map{$0.0}
//状态码
如果fileKeys.count>0{
上载(multipartFormData:{mpForm in
对于自参数中的(k,v){
开关v{
case let fileURL作为URL:
如果让mimeType=self.contentTypeForFormPart(fileURL:fileURL){
追加(fileURL,名称:k,文件名:fileURL.lastPathComponent,mimeType:mimeType)
}
否则{
mpForm.append(文件URL,名称:k)
}
大小写let字符串作为字符串:
mpForm.append(string.data(使用:string.Encoding.utf8)!,名称:k)
案例编号为NSN编号:
mpForm.append(number.stringValue.data(使用:String.Encoding.utf8)!,名称:k)
违约:
fatalError(“带键\(k)的不可处理值\(v)”)
}
}
},to:URLString,方法:xMethod!,头:nil,encodingCompletion:{encodingResult in
开关编码结果{
成功案例(让我们上传,,u):
如果让onProgressReady=self.onProgressReady{
onProgressReady(upload.uploadProgress)
}
processRequest(请求:上传、管理、完成)
案例失败(let encodingError):
var statusCode=编码结果
如果let error=将error编码为?AFError{
//statusCode=错误。\ u code//statusCode private
开关错误{
case.invalidURL(let url):
打印(“无效URL:\(URL)-\(错误.本地化描述)”)
案例.ParameterEncoding失败(原因):
打印(“参数编码失败:\(错误。localizedDescription)”)
打印(“失败原因:\(原因)”)
case.multipartencoding失败(原因):
打印(“多部分编码失败:\(错误。localizedDescription)”)
打印(“失败原因:\(原因)”)
案例.responseValidationFailed(让原因):
打印(“响应验证失败:\(错误。localizedDescription)”)
打印(“失败原因:\(原因)”)
切换原因{
case.dataFileNil、.dataFileReadFailed:
打印(“无法读取下载的文件”)
case.missingContentType(让可接受的ContentType):
打印(“缺少内容类型:\(可接受的内容类型)”)
case.unacceptableContentType(let acceptableContentType,let responseContentType):
打印(“响应内容类型:\(响应内容类型)不可接受:\(可接受内容类型)”)
案例.不可接受状态代码(let代码):
打印(“响应状态代码不可接受:\(代码)”)
//状态代码=代码
}
案例.响应序列化失败(让原因):
打印(“响应序列化失败:\(错误。localizedDescription)”)
打印(“失败原因:\(原因)”)
//状态代码=3840???可能。。
}
打印(“基础错误:\(错误。基础错误)”)
}否则,如果let error=将error编码为?AFError{
打印(“发生URL错误:\(错误)”)
}否则{
打印(“未知错误:\(将错误编码为?AFError)”)
}
打印(状态代码)
完成(nil,ErrorResponse.error(415,nil,encodingError))
}
})
}否则{
let request=makeRequest(管理器:管理器,方法:xMethod!,编码:编码,头:头)
如果让onProgressReady=self.onProgressReady{
onProgressReady(request.progress)
}
processRequest(请求:请求、managerId、完成)
}
}

EXC_BAD_ACCESS

您应该发布崩溃堆栈跟踪。(F i r e b a s e/F i r e s t o r e][i-F s t 2 0 0 0 1]无法到达Cloud Fire store后端。后端在10秒内没有响应。这表明我们的设备目前没有正常的Internet连接。客户端将以脱机模式运行,直到能够成功完全连接到后端