总结两个方法 获取手机型号 以及手机分辨率
#import "sys/utsname.h"
-(NSString*)deviceResolution{
return [[NSStringalloc]initWithFormat:@"%f*%f",[UIScreenmainScreen].bounds.size.width,[UIScreenmainScreen].bounds.size.height];
}
- (NSString*)deviceString
{
// 需要#import "sys/utsname.h"
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSStringstringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];
if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([deviceString isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
if ([deviceStringisEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4";
if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([deviceString isEqualToString:@"iPad1,1"]) return @"iPad";
if ([deviceString isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
if ([deviceString isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([deviceString isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([deviceString isEqualToString:@"i386"]) return @"Simulator";
if ([deviceString isEqualToString:@"x86_64"]) return @"Simulator";
NSLog(@"NOTE: Unknown device type: %@", deviceString);
return deviceString;
}
判断系统版本号:
var systemVersion:String = UIDevice.currentDevice().systemVersion
获取bundle id
var infoDict:NSDictionary = NSBundle.mainBundle().infoDictionary!
var systemVersion:String = UIDevice.currentDevice().systemVersion
tokenInfo.params["osVersion"]=infoDict.objectForKey("CFBundleVersion")
获取当前手机是哪个型号的手机最常用的方法就是获取手机的point。
[ [ UIScreen mainScreen ]bounds ].size.height
#define IS_IPHONE_5 ( fabs(( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) <DBL_EPSILON )
if( IS_IPHONE_5 )
{}
else
{}
#define IS_IPHONE ( [ [ [ UIDevice currentDevice ] model] isEqualToString: @"iPhone" ] )
#define IS_IPOD ( [ [ [ UIDevice currentDevice ] model ]isEqualToString: @"iPod touch" ] )
if( [ [ UIScreen mainScreen ] respondsToSelector:@selector( nativeBounds ) ] )
{
/* Detect usingnativeBounds - iOS 8 and greater */
}
else
{
/* Detect usingbounds - iOS 7 and lower */
}
#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreenmainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreenmainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON )
#define IS_WIDESCREEN ( ( [ [ UIScreen mainScreen ]respondsToSelector: @selector( nativeBounds ) ] ) ? IS_WIDESCREEN_IOS8 :IS_WIDESCREEN_IOS7 )
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() ==UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() ==UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >=2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH,SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH,SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE &&SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE &&SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE &&SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P(IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
各种设备的特点
iPhone 6 Plus 736x414 points 2208x1242pixels 3x scale 1920x1080 physical pixels 401 physical ppi 5.5"
iPhone 6 667x375 points 1334x750pixels 2x scale 1334x750 physical pixels 326 physical ppi 4.7"
iPhone 5 568x320 points 1136x640pixels 2x scale 1136x640 physical pixels 326 physical ppi 4.0"
iPhone 4 480x320 points 960x640pixels 2x scale 960x640 physical pixels 326 physical ppi 3.5"
iPhone 3GS 480x320 points 480x320 pixels 1x scale 480x320 physical pixels 163 physical ppi 3.5"
设备匹配方法:
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone){
if ([[UIScreenmainScreen] respondsToSelector: @selector(scale)])
{
if([[UIScreen mainScreen] nativeBounds].size.height == 960 || [[UIScreenmainScreen] nativeBounds].size.height == 480){
printf("Device Type : iPhone 4,4s ");
}elseif([[UIScreen mainScreen] nativeBounds].size.height == 1136){
printf("Device Type : iPhone 5,5S/iPod 5 ");
}else if([[UIScreenmainScreen] nativeBounds].size.height == 1334){
printf("Device Type : iPhone 6 ");
}elseif([[UIScreen mainScreen] nativeBounds].size.height == 2208){
printf("Device Type : iPhone 6+ ");
}
}
}else{
printf("Device Type : iPad");
}