当前位置:首页 > 操作系统 > Ios

iOS开发技巧-版本比较

1、获取App当前的版本信息

#define XcodeAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

这是Umeng统计提供的宏定义,在使用Umeng的时候,需要设置App版本信息,如下所示,

[MobClick setAppVersion:XcodeAppVersion]; //参数为NSString * 类型,自定义app版本信息,如果不设置,默认从CFBundleVersion里取

2、iOS系统版本比较,

#define kSystemVersion              [[UIDevice currentDevice] systemVersion]

这个宏可以获取iOS的版本信息,例如5.0.1或者5.1等等

NSString *currentSystemVersion = kSystemVersion;
if ([currentSystemVersion compare:@"5.1"] != NSOrderedAscending) {
    //当前iOS版本大于5.1
}else if ([currentSystemVersion compare:@"5.0.1"] != NSOrderedAscending) {
    //当前iOS版本大于5.0.1
}

NSOrderedAsceding文档的解释如下,

技术分享

(The left operand is smaller than the right operand,左侧的参数小于右侧的参数)

这种比较方法很方便,不仅可以进行5.1与6.1的比较,还可以细化到5.1和5.0.1版本的比较。之所以需要细化,是因为每一个小版本之间,sdk还有有一些差异的,就比如避免文件被备份到iCloud,实现方式在5.1和5.0.1不同。

原文:http://my.oschina.net/leejan97/blog/393647


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!