判断iOS 用户设备是iPhone, iPad 还是iPod touch

  • 先放代码,判断依据放后面
  • 代码参考如下:
#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"

你可能感兴趣的:(判断iOS 用户设备是iPhone, iPad 还是iPod touch)