Swift + AFNetworking获取天气信息
课程地址 http://www.imooc.com/video/2475 如何实现xcode8.3,swift3.0+ 环境需要做如下步骤才可以看到信息
self.updateWeatherInfo(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude,appid: "4f4be8fe7031dddd5dec789e01c1b3ac")
func updateWeatherInfo(latitude: CLLocationDegrees,longitude: CLLocationDegrees,appid: String) {
let manager = AFHTTPSessionManager()
let url = "http://api.openweathermap.org/data/2.5/weather"
let params = ["lat": latitude,"lon": longitude,"appid": appid,"cnt": 0] as [String : Any]
manager.get(url,parameters: params,progress: {(progress: Progress) in print("progress")},success: {(operation:URLSessionDataTask!,responSEObject: Any!)
in print("JSON: " + (responSEObject as AnyObject).description)},failure: {(operation:URLSessionDataTask?,error: Error!)
in print("Error: " + error.localizedDescription)})
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |