Created
October 13, 2021 09:09
-
-
Save adamski/2de56d026837c96400552b260bfe7cf9 to your computer and use it in GitHub Desktop.
Check if iOS app update available
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
// 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