MKWeatherUndergroundKit 0.8.11

MKWeatherUndergroundKit 0.8.11

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2016年1月

Mendy Krinsky 维护。



这是一个简单的 iOS 和 OS X 库,用于通过使用 Weather Underground API 获取天气信息

入门

您需要一个 Weather Underground API key 来开始。

获取当前条件

    //Get the location
    CLGeocoder *geocoder = [CLGeocoder new];
    [geocoder geocodeAddressString:@"New York" completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = [placemarks firstObject];

        //Initialize request
        MKWeatherRequest *request = [MKWeatherRequest requestWithType:MKWeatherRequestTypeCurrentConditions
                                                             location:placemark.location];
        request.weatherUndergroundApiKey = @"API_KEY_HERE";
        [request performRequestWithHandler:^(NSError *error, id responseObject) {
            MKWeatherCondition *currentConditions = responseObject;
            //Use currentConditions object here
        }];
    }];

获取未来 36 小时的预报

    CLGeocoder *geocoder = [CLGeocoder new];
    [geocoder geocodeAddressString:@"San Francisco" completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = [placemarks firstObject];

        MKWeatherRequest *request = [MKWeatherRequest requestWithType:MKWeatherRequestTypeHourly
                                                             location:placemark.location];
        request.weatherUndergroundApiKey = @"API_KEY_HERE";
        [request performRequestWithHandler:^(NSError *error, id responseObject) {
            NSArray *hours = responseObject;
            //Array of MKWeatherCondition Objects
        }];
    }];

获取未来 3 天的预报

    CLGeocoder *geocoder = [CLGeocoder new];
    [geocoder geocodeAddressString:@"London, England" completionHandler:^(NSArray *placemarks, NSError *error)     {
        CLPlacemark *placemark = [placemarks firstObject];

        MKWeatherRequest *request = [MKWeatherRequest requestWithType:MKWeatherRequestType3DayForecast
                                                             location:placemark.location];
        request.weatherUndergroundApiKey = @"API_KEY_HERE";
        [request performRequestWithHandler:^(NSError *error, id responseObject) {
            NSArray *threeDayForecast = responseObject;
            //Here responseObject is an array that contains 4 objects: tonight, and the next three days.

            MKWeatherCondition *tonightsConditions = [threeDayForecast firstObject];

            NSLog(@"%f", tonightsConditions.highTemp.c);
            NSLog(@"%f", tonightsConditions.lowTemp.c);
            NSLog(@"%ld", (long)tonightsConditions.averageHumudity);

        }];
    }];

获取未来 3 天的小型预报概述

    CLGeocoder *geocoder = [CLGeocoder new];
    [geocoder geocodeAddressString:@"New Mexico" completionHandler:^(NSArray *placemarks, NSError *error)     {
        CLPlacemark *placemark = [placemarks firstObject];

        MKWeatherRequest *request = [MKWeatherRequest requestWithType:MKWeatherRequestType3DayForecastSummary
                                                             location:placemark.location];
        request.weatherUndergroundApiKey = @"API_KEY_HERE";
        [request performRequestWithHandler:^(NSError *error, id responseObject) {
            NSArray *threeDayForecast = responseObject;
            //Here responseObject is an array which contains 8 objects

            MKWeatherCondition *condition = [threeDayForecast firstObject];
            NSLog(@"%@", condition.generalTimeOfDayTitle);
            NSLog(@"%@", condition.fullSummaryC);
            NSLog(@"%@", condition.fullSummaryF);

        }];
    }];

Climacons

MKWeatherCondition 对象有一个 climacon 属性,其中包含适合天气条件描述的 climacon 字符映射。Climacons 字体是由 Adam Whitcroft 创建的字体集,包括各种与天气相关的图标。为了使用 climacon 属性,请下载 Climacons 字体并将其添加到您的项目中。

依赖项

此库使用 Core Location 来执行请求。

架构

MKWeatherCondition - 通用天气条件

MKWeatherParser - 解析从 Weather Underground API 收到的天气信息

MKWeatherRequest - 表示对 Weather Underground API 的单个请求

感谢

Kevin Mindeguia 提供的 NSDictionary/NSArray 分类。

Comyar Zaheri 提供的 Climacons.h 文件和 Climacons 描述。

许可证

查看 License 文件