2012-09-21 58 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的,你應該使用反正這個。