【发布时间】:2012-09-14 04:22:39
【问题描述】:
有没有办法知道我是在 iOS 5(或更低版本)还是 6(或更高版本)中运行?
我在 iOS 5 中使用 Google API 进行导航,我想在 iOS 6 中使用 Apple 的。
【问题讨论】:
有没有办法知道我是在 iOS 5(或更低版本)还是 6(或更高版本)中运行?
我在 iOS 5 中使用 Google API 进行导航,我想在 iOS 6 中使用 Apple 的。
【问题讨论】:
您可以从以下位置获取 iOS 版本:
[[UIDevice currentDevice] systemVersion]
一般来说,测试您需要的功能是否可用,而不是依赖于特定的 iOS 版本,这是一种更好的做法。正如@mprivat 提到的,NSClassFromString 是实现此目的的一种方法。
【讨论】:
寻找新操作系统中引入的特定类,而不是尝试向操作系统本身询问版本。
例如:
if (NSClassFromString(@"UICollectionView")) {
// It's iOS 6
}
【讨论】:
由于您正在针对 iOS 5 进行编程,因此您可以使用更新的方法来检查弱链接库,只需调用类的 class 方法,如果不支持则返回 nil。
举个例子(取自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,无论如何您都应该使用它。
【讨论】:
这回答了你的问题。检查 iPhone iOS 版本 https://stackoverflow.com/a/5337804/1368748
【讨论】: