Skip to content

Instantly share code, notes, and snippets.

@andrewgarn
Last active December 12, 2015 02:28
Show Gist options
  • Save andrewgarn/4698826 to your computer and use it in GitHub Desktop.
Save andrewgarn/4698826 to your computer and use it in GitHub Desktop.
Checking for iOS update on app store
NSString *requestPath = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", @"528968746"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:requestPath]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *results = [responseObject objectForKey:@"results"];
if (results && [results isKindOfClass:[NSArray class]] && [results count] > 0) {
NSString *resultVersion = [[results objectAtIndex:0] objectForKey:@"version"];
NSString *installedVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
if ([installedVersion compare:resultVersion options:NSNumericSearch] == NSOrderedAscending) {
NSLog(@"Out of date. (%@). Update to %@", installedVersion, resultVersion);
} else {
NSLog(@"Up to date (%@)", resultVersion);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
}];
[operation start];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment