OWMAPIManager 是一个用于通过基于简单的回调的 API 块获取天气信息的开源 iOS Objective-C 库 OpenWeatherMap。
其主要目的是在更少的代码行中使用 OpenWeatherMap API 请求。
包括以下几个部分
您可以在 OWMAPIManagerExample/OWMAPIManagerExample.xcodeproj 中查看详细的示例使用项目。
#import "OWMHeader.h"
为了与 OpenWeatherMap API 通信,您必须首先生成自己的 API 密钥。请参考 Weather API。
在使用之前,您必须将 API 密钥提供给 OWMAPIManager
。
// 在 "AppDelegate.h" 中打开并设置您的 API_KEY
[[OWMAPISetup shareManager] setApi_Key:@"SETUP_API_KEY"];
有以下几种方法可用于获取当前天气信息。
+ (void)doFetchWeatherByCityName:(NSString *)cityName
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block
+ (void)doFetchWeatherByCityName:(NSString *)cityName
withCountry:(NSString *)countryCode
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block;
+ (void)doFetchWeatherByCityID:(NSString *)cityID
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block;
+ (void)doFetchWeatherByCoordinates:(CLLocationCoordinate2D )coordinate
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block;
+ (void)doFetchWeatherByZipCode:(NSString *)zipCode
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block;
+ (void)doFetchWeatherByZipCode:(NSString *)zipCode
withCountry:(NSString *)countryCode
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block;
+ (void)doFetchWeatherByParams:(NSDictionary *)params
withBlock:(void (^)(OWMCurrentWeather *weather, NSError *error))block
[OWMCurrentWeather doFetchWeatherByZipCode:@"380060" withBlock:^(OWMCurrentWeather *weather, NSError *error) {
if (!error) {
}
}];
请检查 OpenWeatherMap 当前天气 API 的请求和响应参数。
OWMAPIManager 由 Darshan Patel 开发。请通过 电子邮件 告诉我您如何使用这个库以及与此库相关的任何信息。
合并请求非常欢迎,但请遵循几条规则:
MIT 许可证 (MIT)
版权所有 (c) 2015 Darshan Patel
特此授予任何获得本软件及关联文档副本(以下简称“软件”)的人免费使用权,包括但不限于以下权利:使用、复制、修改、合并、出版、分发、再许可和/或销售软件的副本,并允许取得软件的人进行前述行为,前提是遵守以下条件:
上述版权声明和本许可通知应包含在软件的所有副本或主要部分中。
本软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论源于合同、侵权或其它方式,包括但不限于软件或其使用或其他交易产生的。