Quantcast
Channel: Check if my IOS application is updated - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Pramod for Check if my IOS application is updated

$
0
0

Here is a simple code to know if the current version is different (this code work on simulator too.)

-(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;}

Note: Make sure that when you enter the new version in iTunes, this matches the version in the app you are releasing. If not then the above code will always return YES regardless if the user updates.


Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>