Created
January 16, 2017 10:33
-
-
Save fozoglu/80545ec4c74eaa6b56306abf80cab058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)updateAction { | |
NSURLRequest* requestForWeatherData = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=London,UK&APPID=????????????"]]; | |
//NOTE : ???? is here -> openweathermap api key write | |
NSURLSession *session = [NSURLSession sharedSession]; | |
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:requestForWeatherData completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) { | |
NSMutableDictionary *allData = [ NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; | |
NSLog(@"%@ - Error %@", allData,error); | |
//data in serialized view | |
NSString* currentWeather = nil; | |
NSArray* weather = allData[@"weather"]; | |
for (NSDictionary* weatherDictionary in weather) { | |
currentWeather = weatherDictionary[@"main"]; | |
} | |
[self setImageAndTextWithWeather:currentWeather]; | |
}]; | |
[dataTask resume]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment