{
return [[[UIDevice currentDevice] systemVersion] floatValue];
}
+ (BOOL)isIpad
{
return [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad;
}
+ (BOOL)isIphone
{
return [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
}
+ (BOOL)hasCamera
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
//iOS Version
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
//试用方法
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.1")) {
//iOS版本大于等于5.1
}
elseif (SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"5.0"))
{
//iOS版本小于等于5.0
}
else{
//其他版本
}
本文提供了一系列实用的Objective-C代码片段,用于检测iOS设备类型(如iPad、iPhone)、检查设备是否配备摄像头以及判断当前运行的iOS系统版本。通过简单的条件判断,开发者可以针对不同版本的iOS系统进行适配。
285

被折叠的 条评论
为什么被折叠?



