#pragma mark - 判断用户设备是iPhone, iPad 还是iPod touch
- (void)checkCurrentDevice
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
NSString* deviceType = [UIDevice currentDevice].model;
if ([deviceType isEqualToString:@"iPhone"]) {
NSLog(@"设备类型 iPhone");
}else if ([deviceType isEqualToString:@"iPod touch"]) {
NSLog(@"设备类型: iPod touch");
}else{
NSLog(@"其他类型设备");
}
}else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSLog(@"设备类型: iPad");
}else{
NSLog(@"其他类型设备");
}
}
1. UIDevice的userInterfaceIdiom枚举
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
UIUserInterfaceIdiomUnspecified = -1,
UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2), // iPhone and iPod touch style UI
UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2), // iPad style UI
UIUserInterfaceIdiomTV NS_ENUM_AVAILABLE_IOS(9_0), // Apple TV style UI
UIUserInterfaceIdiomCarPlay NS_ENUM_AVAILABLE_IOS(9_0), // CarPlay style UI
};
2. UIDevice属性
@property(nonatomic,readonly,strong) NSString *model; // e.g. @"iPhone", @"iPod touch"
网友评论