码迷,mamicode.com
首页 > 移动开发 > 详细

获取iOS设备名/分辨率

时间:2014-11-25 14:39:56      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   ar   os   sp   for   on   2014   

//https://github.com/SVGKit/SVGKit
//SVGKit -> SVGLength.m

        size_t size;
	sysctlbyname("hw.machine", NULL, &size, NULL, 0);
	char *machine = malloc(size);
	sysctlbyname("hw.machine", machine, &size, NULL, 0);
	NSString *platform = [NSString stringWithUTF8String:machine];
	free(machine);
	
	if( [platform hasPrefix:@"iPhone1"]
	|| [platform hasPrefix:@"iPhone2"]
	|| [platform hasPrefix:@"iPhone3"])
		return 163.0f;
	
	if( [platform hasPrefix:@"iPhone4"]
	|| [platform hasPrefix:@"iPhone5"]
	|| [platform hasPrefix:@"iPhone6"])
		return 326.0f;
    
    //
    // For iPhone6+
    // Added by Gerry 2014.11.22 10:12
    //
    // Note: iPhone6  326ppi
    if( [platform hasPrefix:@"iPhone7"]) {
        return 401.0f;
    }
	
	if( [platform hasPrefix:@"iPhone"]) // catch-all for higher-end devices not yet existing
	{
		NSAssert(FALSE, @"Not supported yet: you are using an iPhone that didn‘t exist when this code was written, we have no idea what the pixel count per inch is!");
		return 326.0f;
	}
	
	if( [platform hasPrefix:@"iPod1"]
	   || [platform hasPrefix:@"iPod2"]
	   || [platform hasPrefix:@"iPod3"])
		return 163.0f;
	
	if( [platform hasPrefix:@"iPod4"]
	   || [platform hasPrefix:@"iPod5"])
		return 326.0f;
	
	if( [platform hasPrefix:@"iPod"]) // catch-all for higher-end devices not yet existing
	{
		NSAssert(FALSE, @"Not supported yet: you are using an iPod that didn‘t exist when this code was written, we have no idea what the pixel count per inch is!");
		return 326.0f;
	}
	
	if( [platform hasPrefix:@"iPad1"]
	|| [platform hasPrefix:@"iPad2"])
		return 132.0f;
	if( [platform hasPrefix:@"iPad3"]
	|| [platform hasPrefix:@"iPad4"])
		return 264.0f;
	if( [platform hasPrefix:@"iPad"]) // catch-all for higher-end devices not yet existing
	{
		NSAssert(FALSE, @"Not supported yet: you are using an iPad that didn‘t exist when this code was written, we have no idea what the pixel count per inch is!");
		return 264.0f;
	}
	
	if( [platform hasPrefix:@"x86_64"])
	{
		DDLogWarn(@"[%@] WARNING: you are running on the simulator; it‘s impossible for us to calculate centimeter/millimeter/inches units correctly", [self class]);
		return 132.0f; // Simulator, running on desktop machine
	}


获取iOS设备名/分辨率

标签:des   http   io   ar   os   sp   for   on   2014   

原文地址:http://my.oschina.net/u/734027/blog/348520

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!