Swift Open Weather Map API 是对 OpenWeatherAPI 的封装
包含头文件
import SwiftOpenWeatherMapAPI
设置 api
// Setup weather api
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY")
// Setup weather api with temperature format
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY", temperatureFormat: .Celsius)
// Setup weather api with temperature format and language
let weatherAPI = WAPIManager(apiKey: "YOUR_API_KEY", temperatureFormat: .Celsius, lang: .English)
目前,这个 api 只是 http-api 的简单封装。
weatherAPI.currentWeatherByCityNameAsJson("London") { (json) -> Void in
//Do something with the data
}
结果是一个从使用 SwiftyJSON 映射 api 数据得来的 JSON
结构体
目前有以下方法可用
按城市名称获取当前天气
public func currentWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)
按坐标获取当前天气
public func currentWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)
按城市名称获取预报
public func forecastWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)
按坐标获取预报
public func forecastWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)
按城市名称获取每日预报
public func dailyForecastWeatherByCityNameAsJson(cityName: String, data: (JSON) -> Void)
按坐标获取每日预报
public func dailyForecastWeatherByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, data: (JSON) -> Void)
按城市名称获取历史数据
public func historicDataByCityNameAsJson(cityName: String, start: NSDate, end: NSDate?, data: (JSON) -> Void)
按坐标获取历史数据
public func historicDataByCoordinatesAsJson(coordinates: CLLocationCoordinate2D, start: NSDate, end: NSDate?, data: (JSON) -> Void)