程序中如何判断iOs的版本

问:

I want to check if the iOS version of the device is greater then the 3.1.3 I tried things like [[UIDevice currentDevice].systemVersion floatValue]

but does not work, I just want a if (version > 3.1.3) { }

Does anybody know how to do this?

Thanks


答:

You can get the OS version using:

[[UIDevice currentDevice] systemVersion]

However, you should avoid relying on the version string as an indication of device or OS capabilities. There is usually a more reliable method of checking whether a particular feature or class is available. For example, you can check if UIPopoverController is available on the current device usingNSClassFromString:

if(NSClassFromString(@"UIPopoverController")) {
    // Do something
}

Some classes, like CLLocationManager and UIDevice, provide methods to check device capabilities:

if([CLLocationManager headingAvailable]) {
    // Do something
}

Apple uses systemVersion in their GLSprite sample code, so my recommendation can't be absolute:

// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
// class is used as fallback when it isn't available.
NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
    displayLinkSupported = TRUE;

Important Note: If for whatever reason you decide that systemVersion is what you want, make sure to treat it as an string or you risk truncating the minor revision number (eg. 3.1.2 -> 3.1).


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值