如果你想开发一个同时支持IOS2和IOS3的应用,那你就需要获取当前的IOS版本了。因为IOS2中的部分方法在IOS3中已被移除。
例如,在旋转开始之后,最后的旋转动画发生之前将会自动调用willAnimateRotationToInterfaceOrientation:duration:方法,而该方法是IOS3中新增的方法,在以前的SDK版本中,可以使用willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:方法,但是,IOS3以前的版本中使用的两段式动画比willAnimateRotationToInterfaceOrientation:duration:方法要慢得多,所以应避免这些方法,除非确实需要在应用程序中支持旧的IOS版本。
用宏指令判断版本号:
#ifdef __IPHONE_3_0
// code
#else
// code
#endif
下面看一个示例
#ifdef __IPHONE_3_0
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration;
#else
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
#endif
}
你还可以通过以下方法获取IOS版本
[[UIDevice currentDevice] systemVersion];
这将会返回IOS的当前版本。
在方法体中判断:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0)
{
// iPhone 3.0 code here
}