Created
January 19, 2014 22:36
-
-
Save sjg/8511942 to your computer and use it in GitHub Desktop.
Various code samples for Google iOS SDK Blog Posts
This file contains 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
NSString* const api_forecast_layers_cap = @"http://datapoint.metoffice.gov.uk/public/data/layer/wxfcs/all/json/capabilities?key=%@"; | |
NSString* const api_obs_layers_cap = @"http://datapoint.metoffice.gov.uk/public/data/layer/wxobs/all/json/capabilities?key=%@"; |
This file contains 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
-(void) selectLayer: (NSString*)layerID withTimeSteps: (NSArray *)timestep_set{ | |
for(NSString *timestep in timestep_set){ | |
NSURL *hourlyCall = [NSURL URLWithString: [NSString stringWithFormat: @"http://datapoint.metoffice.gov.uk/public/data/layer/wxobs/%@/png?TIME=%@Z&key=%@", layerID, timestep, MET_OFFICE_API_KEY]]; | |
NSLog(@"Calling URL: %@", [hourlyCall absoluteString]); | |
NSURLRequest *request = [NSURLRequest requestWithURL: hourlyCall]; | |
AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request]; | |
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { | |
//Check for a UIImage before adding it to the array | |
if([responseObject class] == [UIImage class]){ | |
// Setup our image object and write it to our array | |
SGMetOfficeForecastImage *serverImage = [[SGMetOfficeForecastImage alloc] init]; | |
serverImage.image = [UIImage imageWithData: operation.responseData]; | |
serverImage.timestamp = timestep; | |
serverImage.timeStep = nil; | |
serverImage.layerName = layerID; | |
[overlayArray addObject: serverImage]; | |
// Increment our expected count so that we know when to start playing the animation | |
imagesExpected = @([imagesExpected intValue] + 1); | |
} | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
//We didn't get the image but that won't stop us! | |
imagesExpected = @([imagesExpected intValue] + 1); | |
NSLog(@"Couldn't download image."); | |
}]; | |
[operation start]; | |
// Start the Timer to check that we have all the images we requested downloaded and stored in the layer array | |
checkDownloads = [NSTimer scheduledTimerWithTimeInterval: 1 target:self selector:@selector(checkAllImagesHaveDownloaded:) userInfo: [NSNumber numberWithInt: [timestep_set count]] repeats: YES]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment