如何判断iOS设备型号,比如iPhone5.现在我的做法是写了个宏:#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
2 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
+ (NSString*)getMachine{ size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *name = malloc(size); sysctlbyname("hw.machine", name, &size, NULL, 0); NSString *machine = [NSString stringWithCString:name encoding:NSUTF8StringEncoding]; free(name); if( [machine isEqualToString:@"i386"] || [machine isEqualToString:@"x86_64"] ) machine = @"ios_Simulator"; else if( [machine isEqualToString:@"iPhone1,1"] ) machine = @"iPhone_1G"; else if( [machine isEqualToString:@"iPhone1,2"] ) machine = @"iPhone_3G"; else if( [machine isEqualToString:@"iPhone2,1"] ) machine = @"iPhone_3GS"; else if( [machine isEqualToString:@"iPhone3,1"] ) machine = @"iPhone_4"; else if( [machine isEqualToString:@"iPod1,1"] ) machine = @"iPod_Touch_1G"; else if( [machine isEqualToString:@"iPod2,1"] ) machine = @"iPod_Touch_2G"; else if( [machine isEqualToString:@"iPod3,1"] ) machine = @"iPod_Touch_3G"; else if( [machine isEqualToString:@"iPod4,1"] ) machine = @"iPod_Touch_4G"; else if( [machine isEqualToString:@"iPad1,1"] ) machine = @"iPad_1"; else if( [machine isEqualToString:@"iPad2,1"] ) machine = @"iPad_2"; return machine; }
历史上是这样的
湖上湖
TA贡献2003条经验 获得超2个赞
为什么要判断设备型号?如果是为了适应不同分辨率的需求,我是拿屏幕尺寸
[[UIScreen mainScreen] bounds].size
如果是装逼型需求,比如“用户通过iPhone5分享”,试试
char deviceString[256];size_t size = 255;sysctlbyname("hw.machine", NULL, &size, NULL, 0);if (size > 255) { size = 255; }sysctlbyname("hw.machine", deviceString, &size, NULL, 0);if (strcmp(deviceString,"iPhone1,1") == 0) { etc... } // 2G
iPhone2,1 3GS
iPhone3,1 4
iPhone3,3 4 CDMA
iPhone4,1 4s 猜的
iPhone5,1 5 猜的
- 2 回答
- 0 关注
- 202 浏览
添加回答
举报
0/150
提交
取消