在ResponseSerialization.swift上崩溃(部分申请专门)

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

我在Fabric上遇到这个错误:ResponseSerialization.swift第167行部分申请专门

我认为这与返回给我的JSON格式不同有关。但是我怎么解决呢?

这是Fabric Crashlytics屏幕:Fabric screen

300号线已关闭,但那里没有连接。我想这是一个问题,因为这里没有错误。

ApiManager.sharedInstance.makeRequest(urlString: url, params: nil, success: { (responseString) in
        guard let response = Model(JSONString: responseString) else {
            self.noResult()
            return
        }
     ...
}, errors: { (errorCode) in // ERROR LINE (Line 300)
    self.noResult(errorCode)
})

我还在xCode中的Window> Organizer> Crashes中查看了同样的错误。这些是我的代码和错误行屏幕:enter image description here

enter image description here

我也尝试过try-catch但它没有用,因为代码没有出错。

这是我简化的请求代码:

AFManager = Alamofire.SessionManager(配置:配置)//在AppDelegate中定义。

class ApiManager{
    static let sharedInstance = ApiManager()

    func makeRequest(urlString: String, params: Parameters!, success: @escaping (_ responseObject:String)->() = { _ in }, errors: @escaping (_ errorMessage:String)->() = { _ in } ){

        AFManager.request(urlString, method: .get, parameters: params, headers: headers)
            .responseJSON { response in

                switch response.result {
                case .success:
                    if let status = response.response?.statusCode {
                        switch(status){
                        case 200:

                            guard let response_data = response.data else {
                                errors("\(status)")
                                return
                            }
                            guard let utf8Text = String(data: response_data, encoding: .utf8) else {
                                errors("\(status)")
                                return
                            }
                            success(utf8Text) // ERROR LINE

                            break
                        default:
                            errors("\(status)")

                        }
                    }
                case .failure(let error):
                    errors(String(error._code))
                }
        }
    }
}

Alamofire / ResponseSerialization.swift:https://github.com/Alamofire/Alamofire/blob/master/Source/ResponseSerialization.swift

json swift crash alamofire response
1个回答
0
投票

崩溃是在一个完全不同的地方。结构错误行显示在错误的位置。 Fabric显示了300行的崩溃,但实际上是272行

enter image description here

var coordinate = response.coordinates[0] // Line 272

以下是失败类的代码:

ApiManager.sharedInstance.makeRequest(urlString: url, params: nil, success: { (responseString) in
     guard let response = Model(JSONString: responseString) else {
         self.noResult()
         return
     }
     var coordinate = response.coordinates[0] // ACTUALLY ERROR LINE (Line 272)
     ...
}, errors: { (errorCode) in // FABRIC ERROR LINE (Line 300)
    self.noResult(errorCode)
})
© www.soinside.com 2019 - 2024. All rights reserved.