2012-09-21 57 views
0

有没有办法知道我是否在iOS 5(或更少)或6(或更高版本)中运行?了解iOS版本

我使用谷歌API的方向在iOS 5中,我想用苹果的iOS的6

回答

1

你可以从iOS版本:

[[UIDevice currentDevice] systemVersion] 

在一般情况下,它的更好练习测试您需要的功能是否可用,而不是依赖于特定的iOS版本。正如@mprivat提到的,NSClassFromString是完成这个的一种方法。

1

寻找在新操作系统中引入的特定类,而不是试图向操作系统本身询问版本。

例如:

if (NSClassFromString(@"UICollectionView")) { 
    // It's iOS 6 
} 
1

既然你正在编写针对iOS 5中,你可以使用更最近刚刚调用类的class方法,如果它不支持它返回零的弱链接库检查方法。

为例(从documentation拍摄):

if ([UIPrintInteractionController class]) { 
    // Create an instance of the class and use it. 
} 
else { 
    // The print interaction controller is not available. 
} 

这需要LLVM和Clang的,但你的支持的iOS5和iOS6的,你应该使用反正这个。