Last active
December 12, 2015 02:28
-
-
Save andrewgarn/4698826 to your computer and use it in GitHub Desktop.
Checking for iOS update on app store
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 *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