在AppDelegate方法里,添加类方法
+ (NSInteger)OSVersion;
实现为
+ (NSInteger)OSVersion { static NSUInteger _deviceSystemMajorVersion = -1; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue]; }); return _deviceSystemMajorVersion; }
使用时先导入
#import "AppDelegate.h"
直接使用[AppDelegate OSVersion]获取信息,如7,6等