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