嗨,我在块内调用了block,但应用程序崩溃并出现错误libc++ abi.dylib:以NSException类型的未捕获异常终止。控制台上没有其他描述。找不到问题。
GeocoderApi.shared.getAddress(lat: "\(coordinate.latitude)", lang: "\(coordinate.longitude)", reverseGeocodeHandler: { status, responseObject in
if let locality = responseObject as? String{
WeatherApi.shared.averageForecastName(cityName: locality, completionHandler: { status, responseObject in
LocationManager.shared.stopUpdatingLocation()
if let weatherArray = responseObject as? [Weather]{
if !weatherArray.isEmpty {
self.myJourney.weatherArray.remove(at: 0)
self.myJourney.weatherArray.insert(weatherArray[0], at: 0)
self.myJourney.weatherArray[0].upcomings.append(contentsOf: weatherArray)
self.myJourney.weatherArray[0].upcomings.remove(at: 0)
self.journeyView.reloadWeather()
}
}
})
}
})
func getAddress(lat:String,lang:String,reverseGeocodeHandler:@escaping (_ status:Bool, _ responseObject:Any)->()){
if !ReachabilityManager.shared.isReachable {
let error = WSError()
error.errorTitle = "Network error"
error.errorDescription = "Unable to connect, please check your internet connectivity."
reverseGeocodeHandler(false,error)
return
}
self.showNetworkActivity()
let sessionManager = AFHTTPSessionManager(baseURL: baseUrl, sessionConfiguration: URLSessionConfiguration.default)
sessionManager.requestSerializer = AFJSONRequestSerializer()
sessionManager.responseSerializer = AFJSONResponseSerializer()
let urlPath = getPath(path: "maps/api/geocode/json?latlng=\(lat),\(lang)")
sessionManager.post(urlPath, parameters: nil, progress: { progress in
}, success: { task, responseObject in
var cityName = ""
if let disc = responseObject as? [String:Any]{
cityName = self.Parse(disc: disc)
}
self.hideNetworkActivity()
reverseGeocodeHandler(true,cityName)
}, failure: { operation, err in
self.hideNetworkActivity()
let error = WSError(error: err as NSError)
reverseGeocodeHandler(false,error)
})
}
func averageForecastName(cityName:String,completionHandler:@escaping (_ status:Bool, _ responseObject:Any)->()){
if !ReachabilityManager.shared.isReachable {
let error = WSError()
error.errorTitle = "Network error"
error.errorDescription = "Unable to connect, please check your internet connectivity."
completionHandler(false,error)
return
}
self.showNetworkActivity()
let sessionManager = AFHTTPSessionManager(baseURL: baseUrl, sessionConfiguration: URLSessionConfiguration.default)
sessionManager.requestSerializer = AFJSONRequestSerializer()
sessionManager.responseSerializer = AFJSONResponseSerializer()
let urlPath = getPath(path: "data/2.5/forecast/daily?q=\(cityName)&cnt=6")
sessionManager.post(urlPath, parameters: nil, progress: { progress in
}, success: { task, responseObject in
var weatherArray = [Weather]()
if let disc = responseObject as? [String:Any]{
weatherArray.append(contentsOf: Weather.GetForecasts(rootDisc: disc))
}
self.hideNetworkActivity()
completionHandler(true,weatherArray)
}, failure: { operation, err in
self.hideNetworkActivity()
let error = WSError(error: err as NSError)
completionHandler(false,error)
})
}
最佳答案
通过.addingPercentEncoding(withAllowedCharacters:.urlQueryAllowed)解决了此问题
关于swift - 因错误libc++ abi.dylib而崩溃:以NSException类型的未捕获异常终止,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41186006/