崩溃 ResponseSerialization.swift(部分申请专业)
Crashes on ResponseSerialization.swift (partial apply for specialized)
我在 Fabric 上遇到这个错误:
ResponseSerialization.swift 第 167 行
部分申请专业
我认为这与返回给我的 JSON 格式不同有关。但是我怎么解决呢?
这是 Fabric Crashlytics 屏幕:
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)
})
我也在 Window> Organizer> Crashes in xCode 中查看了同样的错误。这些是我的代码和错误行屏幕:
I also tried try-catch but it did not work because the code did not
fall into error.
这是我的简化请求代码:
AFManager = Alamofire.SessionManager(configuration:配置) //在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
崩溃发生在一个完全不同的地方。织物错误线显示在错误的位置。 Fabric 在 300 行显示崩溃,但实际上是在 272
行
var coordinate = response.coordinates[0] // Line 272
这是失败的代码 class:
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)
})
我在 Fabric 上遇到这个错误: ResponseSerialization.swift 第 167 行 部分申请专业
我认为这与返回给我的 JSON 格式不同有关。但是我怎么解决呢?
这是 Fabric Crashlytics 屏幕:
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)
})
我也在 Window> Organizer> Crashes in xCode 中查看了同样的错误。这些是我的代码和错误行屏幕:
I also tried try-catch but it did not work because the code did not fall into error.
这是我的简化请求代码:
AFManager = Alamofire.SessionManager(configuration:配置) //在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
崩溃发生在一个完全不同的地方。织物错误线显示在错误的位置。 Fabric 在 300 行显示崩溃,但实际上是在 272
行var coordinate = response.coordinates[0] // Line 272
这是失败的代码 class:
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)
})