SmileWeather 0.2.4

SmileWeather 0.2.4

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
Released最后发布2017年5月

‘Rain --description=’11 macbook air维护。




这是一个方便地搜索和解析来自 WundergroundOpenweathermap 的天气数据的库。

它能为您做什么?

1. 处理所有关于搜索和解析天气数据的复杂事务。

例如,您可以使用 -(void)getPlacemarksFromString:(NSString*)string completion:(SmileWeatherPlacemarksCompletion)completion 按照字符串搜索位置,完成块返回 CLPlacemark 的数组。

[[SmileWeatherDownLoader sharedDownloader] getPlacemarksFromString:@"cupertino" completion:^(NSArray *placeMarks, NSError *error) {
        if (!error) {
            //search results: array of placemark in here
        }
    }];

您可以使用 -(void)getWeatherDataFromPlacemark:(CLPlacemark*)placeMark completion:(SmileWeatherDataDownloadCompletion)completion; 来获取位置标记的天气数据,完成块返回格式良好的天气数据 SmileWeatherData

[[SmileWeatherDownLoader sharedDownloader] getWeatherDataFromPlacemark:placemark completion:^(SmileWeatherData *data, NSError *error) {
        if (!error) {
            //Well formed weather data in here.
        }
    }];
2. 无需任何天气图标,SmileWeather 会为您处理。

通过使用 climacons 字体SmileWeatherData 包含了与天气图标对应的字符。

SmileWeatherData *data = ...;
UILabel *iconLabel = ...;

//current weather condition
iconLabel.text = data.currentData.icon;

3. 对世界上几乎所有国家的相关信息进行了完全本地化。

尽可能地将天气信息、时间戳、星期、时区等内容本地化。

4. 支持 Today 扩展和 WatchOS 2。

5. 通过使用 SmileWeatherDemoVC,简单地将天气 Widget 风格 UI 添加到您的项目中。

请查看示例项目以获取更多详细信息。

SmileWeatherDemoVC *demoVC = [SmileWeatherDemoVC DemoVCToView:self.containerView];

理论介绍

主要类是 SmileWeatherDownLoader。它负责从 Wunderground 服务器下载数据。它有三个主要方法:

/*!Get weather data from CLPlacemark.*/
-(void)getWeatherDataFromPlacemark:(CLPlacemark*)placeMark completion:(SmileWeatherDataDownloadCompletion)completion;

/*!Get weather data from CLLocation.*/
-(void)getWeatherDataFromLocation:(CLLocation*)location completion:(SmileWeatherDataDownloadCompletion)completion;

/*!Get array of CLPlacemark from the input string.*/
-(void)getPlacemarksFromString:(NSString*)string completion:(SmileWeatherPlacemarksCompletion)completion;

SmileWeatherDataDownloadCompletion 块中,返回 SmileWeatherData,其中包含当前天气数据、4天天气预报数据、24小时天气预报数据等。

[[SmileWeatherDownLoader sharedDownloader] getWeatherDataFromPlacemark:placemark completion:^(SmileWeatherData *data, NSError *error) {
        if (!error) {
            NSLog(@"Current Temperature, Celsius : %@, Fahrenheit: %@", data.currentData.currentTempStri_Celsius, data.currentData.currentTempStri_Fahrenheit);
        }
    }];

SmileWeatherData 还遵守 NSCoding,您可以将其存档为 NSData

SmileWeatherData *data = ...
NSData* encodedData = [NSKeyedArchiver archivedDataWithRootObject: data];

如何将其用于您的项目?

步骤1. 通过 CocoaPods 使用 SmileWeather。要安装它,只需将以下行添加到您的 Podfile 中

pod 'SmileWeather'

或者,您可以将 SmileWeather 文件夹拖放到您的项目中。

步骤2. 注册 WundergroundOpenweathermap 以获取 API 密钥。

步骤3. 按照以下图片添加 API 密钥和 climacons 字体 到您的项目的 Info.plist 中。

如果您使用的是 Wunderground API,请添加此密钥:API_KEY_wunderground

如果您使用的是 Openweathermap API,请添加此密钥:API_KEY_openweathermap

如果您在 Info.plist 中添加了这两个密钥,请添加 API_NOW 以告知 SmileWeather 应使用哪个,0 代表 API_KEY_wunderground,而 1 代表 API_KEY_openweathermap

步骤4. 最后一步是将 SmileWeatherDownLoader.h 导入到您的项目中,并开始使用它 :)。

贡献

  • 热烈欢迎提交 pull request。

联系

  • 如果您有任何建议或发现某些问题,请与我联系。
  • 电子邮箱 liu044100@gmail.com

感谢

感谢 Comyar Zaheri 的 Sol° for iOS,我从这个项目中受到了启发。

感谢 climacons 字体

许可

SmileWeather 可以在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。