How IOS compares the version number size

Source: Internet
Author: User

Compare iOS version number size eg:3.2.0 and 3.1.0 or 3.2.0 and 3.2
Returns the BOOL value variable Yes or NO

In the app iteration update process, there is the need to compare the size of the version number, and then pop-up prompts for updates.

The previous version number has always been the same as the number of 1.1.0----and 1.1.2. This is done by deleting the. Number in the version number string, comparing the size of the two numbers, and later discovering that in the App Store, the version numbers of various apps vary in different formats, 1.0.11-->1.1.0, if you also compare the version number with the above method, the 1011 (local version) is definitely greater than 110 (on-line), while the actual 1.1.0 is the next version of 1.0.11.

Workaround:

Version number is divided into three modules to name, so the comparison size or three parts cut open to compare size compatibility, in case the version number is not named in accordance with the prescribed format, then the size of the wrong judgment.

The idea is this: three parts, starting with the first part comparing size, Priority: Part One > Second part > Third part, once the size of the comparison is the end, as long as the previous part of the big, no matter how small in the back part of the matter.

-(BOOL) comparevesionwithserverversion: (nsstring *) version{

nsarray *versionarray = [version componentsseparatedbystring:@ ".] ]; //Server return version

Nsarray *currentvesionarray = [app_version componentsseparatedbystring:@ "."]; //Current version

Nsinteger a = (Versionarray. Count> Currentvesionarray. count)? Currentvesionarray. Count:versionarray. count;

For (int i = 0; i< A; i++) {

Nsinteger a = [[versionarray safeobjectatindex:i] integervalue];

Nsinteger b = [[currentvesionarray safeobjectatindex:i] integervalue];

if (a > B) {

NSLog (@ "with new version");

return YES;

}Else if (a < b) {

return NO;

}

return NO;

}

How IOS compares the version number size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.