比较具有格式“2.0.1”,“2.0.09”的字符串, [英] Comparing strings with the format "2.0.1", "2.0.09"
问题描述
我需要获取用户的应用版本号,并将其与我服务器上的当前应用版本进行比较。如果用户的应用程序版本较低,他会得到一个弹出窗口来更新他的应用程序。在执行此操作时,我需要比较应用程序的版本与可用的版本。如何比较格式2.0.1
和2.0.09
的字符串,并得到最高的一个,在Objective-C?
I need to get the user's app version number and compare it with the current app version on my server. If the user's app version is lower, then he will get a pop-up to update his app. While doing this, I need to compare the version of the app with the versions that are available. How can I compare the strings which are in the format "2.0.1"
and "2.0.09"
and get the highest one, in Objective-C?
推荐答案
如果你的字符串都是2.0.1可以只使用正确的选项进行比较:
If your strings are all of the form "2.0.1" etc. you can just compare them as is with the right options:
([localVersionString compare:currentVersionString
options:NSNumericSearch] != NSOrderedAscending);
上述会返回 YES
if localVersion不早于服务器上的currentVersion,否则为 NO
(假设我有正确的方式)。
The above would return "YES
" if the localVersion is no older than the currentVersion on the server, and "NO
" otherwise (assuming I have this the right way round).
这是在检查安装在iDevice上的iOS的本地版本时通常要做的事情。
This is the usual thing to do when checking the local version of iOS installed on an iDevice.
这篇关于比较具有格式“2.0.1”,“2.0.09”的字符串,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!