iOS 判断机型是否为 iPhone X、XR、XS、XS Max 的方法
if ([deviceString isEqualToString:@"iPhone10,1"]) return @"国行(A1863)、日行(A1906)iPhone 8";
if ([deviceString isEqualToString:@"iPhone10,4"]) return @"美版(Global/A1905)iPhone 8";
if ([deviceString isEqualToString:@"iPhone10,2"]) return @"国行(A1864)、日行(A1898)iPhone 8 Plus";
if ([deviceString isEqualToString:@"iPhone10,5"]) return @"美版(Global/A1897)iPhone 8 Plus";
if ([deviceString isEqualToString:@"iPhone10,3"]) return @"国行(A1865)、日行(A1902)iPhone X";
if ([deviceString isEqualToString:@"iPhone10,6"]) return @"美版(Global/A1901)iPhone X";
if ([deviceString isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
if ([deviceString isEqualToString:@"iPhone11,4"]) return @"iPhone XS Max";
if ([deviceString isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";
if ([deviceString isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
参考原文:
史上最全的iOS各种设备信息获取总结
信息采集框架
iPhone XR/iPhone XS Max启动图
iPhone XR:828px x 1792px
iPhone XS Max: 1242px x 2688px
代码中判断是否是iPhone X时需要注意
如果你以前是使用设备尺寸来判断iPhone X那就需要修改了,判断iPhone X主要是因为刘海的原因可能要做些特殊处理。鉴于iPhone X/XS/XR/XS Max底部都会有安全距离,所以可以利用safeAreaInsets.bottom > 0.0来判断是否是iPhone X/XS/XR/XS Max。
safeAreaInsets支持iOS11及以后。
#define IPHONE_X (@available(iOS 11.0, *)?[[[UIApplication sharedApplication] delegate] window].safeAreaInsets.bottom > 0.0:NO )