0
有没有办法将CFBundleVersion变量(一个NSString)更改为浮动。iOS CFBundleVersion浮动
我的版本目前是'1.0.2',但是当我从它解析floatValue时,它将返回1.00000。
如何解析它,所以我会得到这个值:1.02000
谢谢。
有没有办法将CFBundleVersion变量(一个NSString)更改为浮动。iOS CFBundleVersion浮动
我的版本目前是'1.0.2',但是当我从它解析floatValue时,它将返回1.00000。
如何解析它,所以我会得到这个值:1.02000
谢谢。
这是不可能的。有两个小数点,并没有明确的方式来表示它作为一个浮点数。你可能会推出你自己的代码来将它转换为,这个东西是,但基本上这种方法是有缺陷的。
试试这个: -
CGFloat versionNumber;
NSArray *versionItems = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if (versionItems.count == 3)
{
NSInteger major = [[versionItems objectAtIndex:0] integerValue];
NSInteger minor = [[versionItems objectAtIndex:1] integerValue];
NSInteger bug = [[versionItems objectAtIndex:2] integerValue];
versionNumber = [[NSString stringWithFormat:@"%ld.%ld%ld",(long)major,(long)minor,(long)bug] floatValue];
}
else
{
versionNumber = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] floatValue];
}
你为什么要这么做? – Bemmu
我想知道我的应用程序自上次启动以来是否已更新。 –
由于你不降级,对平等的检查往往足够好。 – Eiko