如何判断iOS设备型号,比如iPhone5.现在我的做法是写了个宏:#defineiPhone5([UIScreeninstancesRespondToSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(640,1136),[[UIScreenmainScreen]currentMode].size):NO)API中直接有方法可以调用吗?
2 回答
智慧大石
TA贡献1946条经验 获得超3个赞
+(NSString*)getMachine{size_tsize;sysctlbyname("hw.machine",NULL,&size,NULL,0);char*name=malloc(size);sysctlbyname("hw.machine",name,&size,NULL,0);NSString*machine=[NSStringstringWithCString:nameencoding:NSUTF8StringEncoding];free(name);if([machineisEqualToString:@"i386"]||[machineisEqualToString:@"x86_64"])machine=@"ios_Simulator";elseif([machineisEqualToString:@"iPhone1,1"])machine=@"iPhone_1G";elseif([machineisEqualToString:@"iPhone1,2"])machine=@"iPhone_3G";elseif([machineisEqualToString:@"iPhone2,1"])machine=@"iPhone_3GS";elseif([machineisEqualToString:@"iPhone3,1"])machine=@"iPhone_4";elseif([machineisEqualToString:@"iPod1,1"])machine=@"iPod_Touch_1G";elseif([machineisEqualToString:@"iPod2,1"])machine=@"iPod_Touch_2G";elseif([machineisEqualToString:@"iPod3,1"])machine=@"iPod_Touch_3G";elseif([machineisEqualToString:@"iPod4,1"])machine=@"iPod_Touch_4G";elseif([machineisEqualToString:@"iPad1,1"])machine=@"iPad_1";elseif([machineisEqualToString:@"iPad2,1"])machine=@"iPad_2";returnmachine;}历史上是这样的
添加回答
举报
0/150
提交
取消