TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2016 |
Maintained by Mendy Krinsky.
A simple iOS and OS X library for retrieving weather information using the Weather Underground API
You'll need a Weather Underground API key to start.
//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
}];
}];
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
}];
}];
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);
}];
}];
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);
}];
}];
MKWeatherCondition
objects have a climacon
property that contains an appropriate climacon character mapping for the weather condition description. The Climacons Font is a font set created by Adam Whitcroft featuring various weather-related icons. In order to use the climacon
property, download the Climacons font and add it to your project.
This library uses Core Location
to perform requests.
MKWeatherCondition
- A generic weather condition
MKWeatherParser
- Parses the weather information received from the Weather Underground API
MKWeatherRequest
- Represents a single request to the Weather Underground API
Kevin Mindeguia for the NSDictionary/NSArray categories.
Comyar Zaheri for the Climacons.h
file and the Climacons
description.
See the License
file