Skip to content

Instantly share code, notes, and snippets.

@adamski
Created October 13, 2021 09:09
Show Gist options
  • Save adamski/2de56d026837c96400552b260bfe7cf9 to your computer and use it in GitHub Desktop.
Save adamski/2de56d026837c96400552b260bfe7cf9 to your computer and use it in GitHub Desktop.
Check if iOS app update available
// From https://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version-on-appstore
-(BOOL) needsUpdate{
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([lookup[@"resultCount"] integerValue] == 1){
NSString* appStoreVersion = lookup[@"results"][0][@"version"];
NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
if (![appStoreVersion isEqualToString:currentVersion]){
NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
return YES;
}
}
return NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment