2

How can I compare installed iOS version with the latest iOS version programatically using objective-c?

Omkar
  • 165
  • 6
  • You can use itunes search api to look for you app in itunes. Or you can put somewhere in cloud you current app version. – Cy-4AH Jan 11 '18 at 10:36
  • @Cy-4AH He's talking about the iOS version, not his app's version. – Milan Nosáľ Jan 11 '18 at 10:40
  • 3
    may be help you.. https://stackoverflow.com/questions/3339722/how-to-check-ios-version/3339787 – Nirav Kotecha Jan 11 '18 at 10:56
  • First of, why do this? Second, be careful when you do this, the device your app is running on might not be able to run the latest version of iOS. Especially if you want to inform the user. If your app needs a specific version of iOS you set that as your deployment version. – rckoenes Jan 11 '18 at 10:59
  • There isn't anything available in iOS that provides you the latest version of the iOS. Obviously there must be an API which Settings app uses to do the same. But I don't think that would be available publicly. You can manage your server to keep the latest version of the iOS – Inder Kumar Rathore Jan 11 '18 at 11:37

1 Answers1

1

You have to take new version number from web service.This is because if you want to update app from app store then you just need to increase your app version from your pannel and you will get it in web service and then you can check it like this (call this method by passing web service version) :-

(BOOL)isUpdateAvailable:(NSString*)latestVersion 
{ 
    NSString *currentAppVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

    NSArray *myCurrentVersion = [currentAppVersion componentsSeparatedByString:@"."];
    NSArray *myLatestVersion = [latestVersion componentsSeparatedByString:@"."];
    NSInteger legthOfLatestVersion = myLatestVersion.count;
    NSInteger legthOfCurrentVersion = myCurrentVersion.count;
    if (legthOfLatestVersion == legthOfCurrentVersion)
    {
        for (int i=0; i<myLatestVersion.count; i++)
        {
            if ([myCurrentVersion[i] integerValue] < [myLatestVersion[i] integerValue])
            {
                return true;
            }
            else if ([myCurrentVersion[i] integerValue] == [myLatestVersion[i] integerValue])
            {
                continue;
            }
            else
            {
               return false;
            }
        }
        return false;
    }
    else
    {
        NSInteger count = legthOfCurrentVersion > legthOfLatestVersion ? legthOfLatestVersion : legthOfCurrentVersion;
        for (int i=0; i<count; i++)
        {
            if ([myCurrentVersion[i] integerValue] < [myLatestVersion[i] integerValue])
            {
                return true;
            }
            else if([myCurrentVersion[i] integerValue] > [myLatestVersion[i] integerValue])
            {
                return false;
            }
            else if ([myCurrentVersion[i] integerValue] == [myLatestVersion[i] integerValue])
            {
                continue;
            }
        }

        if (legthOfCurrentVersion < legthOfLatestVersion)
        {
            for (NSInteger i=legthOfCurrentVersion; i<legthOfLatestVersion; i++)
            {
                if ([myLatestVersion[i] integerValue] != 0)
                {
                    return YES;
                }
            }
            return NO;
        }
        else
        {
            return NO;
        }
    }
}

This will return bool value if it will return YES then you will have new version of your app and if NO then your app has updated version.

Raj Oriya
  • 78
  • 4