判断苹果各种智能手机设备型号

来源:互联网 发布:广州中名软件 编辑:程序博客网 时间:2024/05/16 04:39
enum {    UIDeviceResolution_Unknown          = 0,    UIDeviceResolution_iPhoneStandard   = 1,    // iPhone 1,3,3GS Standard Display      (320x480px)    UIDeviceResolution_iPhoneRetina35   = 2,    // iPhone 4,4S Retina Display 3.5"      (640x960px)    UIDeviceResolution_iPhoneRetina4    = 3,    // iPhone 5 Retina Display 4"           (640x1136px)    UIDeviceResolution_iPhoneRetina47   = 4,    // iPhone 6,4S Retina Display 4.7"      (750x1334px)    UIDeviceResolution_iPhoneRetina55   = 5,    // iPhone 6 plus Retina Display 5.5"    (1242x2208px)    UIDeviceResolution_iPadStandard     = 6,    // iPad 1,2 Standard Display            (1024x768px)    UIDeviceResolution_iPadRetina       = 7     // iPad 3 Retina Display                (2048x1536px)}; typedef NSUInteger UIDeviceResolution;#import <UIKit/UIKit.h>@interface UIDevice (Extras)@end@interface UIDevice (Resolution)+ (UIDeviceResolution)resolution;+ (NSString *)deviceType;@end
#import "UIDevice+Extras.h"#include <sys/types.h>#include <sys/sysctl.h>typedef NS_ENUM(NSUInteger, NTNUDeviceType) {    DeviceAppleUnknown,    DeviceAppleSimulator,    DeviceAppleiPhone,    DeviceAppleiPhone3G,    DeviceAppleiPhone3GS,    DeviceAppleiPhone4,    DeviceAppleiPhone4S,    DeviceAppleiPhone5,    DeviceAppleiPhone5C,    DeviceAppleiPhone5S,    DeviceAppleiPhone6,    DeviceAppleiPhone6_Plus,    DeviceAppleiPodTouch,    DeviceAppleiPodTouch2G,    DeviceAppleiPodTouch3G,    DeviceAppleiPodTouch4G,    DeviceAppleiPad,    DeviceAppleiPad2,    DeviceAppleiPad3G,    DeviceAppleiPad4G,    DeviceAppleiPad5G_Air,    DeviceAppleiPadMini,    DeviceAppleiPadMini2G};@implementation UIDevice (Extras)@end@implementation UIDevice (Resolution)+ (UIDeviceResolution)resolution{    UIDeviceResolution resolution = UIDeviceResolution_Unknown;    UIScreen *mainScreen = [UIScreen mainScreen];    CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);    CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){        if (scale == 3.0f) {            if (pixelHeight == 2208.0f)                resolution = UIDeviceResolution_iPhoneRetina55;                    }else if (scale == 2.0f) {            if (pixelHeight == 960.0f)                resolution = UIDeviceResolution_iPhoneRetina35;            else if (pixelHeight == 1136.0f)                resolution = UIDeviceResolution_iPhoneRetina4;            else if (pixelHeight == 1334.0f)                resolution = UIDeviceResolution_iPhoneRetina47;                    } else if (scale == 1.0f && pixelHeight == 480.0f)            resolution = UIDeviceResolution_iPhoneStandard;            } else {        if (scale == 2.0f && pixelHeight == 2048.0f) {            resolution = UIDeviceResolution_iPadRetina;                    } else if (scale == 1.0f && pixelHeight == 1024.0f) {            resolution = UIDeviceResolution_iPadStandard;        }    }        return resolution;}+ (NSString *)deviceType{        size_t size;    sysctlbyname("hw.machine", NULL, &size, NULL, 0);    char *machine = (char*)malloc(size);    sysctlbyname("hw.machine", machine, &size, NULL, 0);    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];    //    NSDictionary *dic = @{//                          @"i386": @"Simulator",//                          @"x86_64": @"Simulator",//                          @"iPod1,1": @"iPodTouch",//                          @"iPod2,1": @"iPodTouch2G",//                          @"iPod3,1": @"iPodTouch3G",//                          @"iPod4,1": @"iPodTouch4G",//                          @"iPhone1,1": @"iPhone",//                          @"iPhone1,2": @"iPhone3G",//                          @"iPhone2,1": @"iPhone3GS",//                          @"iPhone3,1": @"iPhone4",//                          @"iPhone3,3": @"iPhone4",//                          @"iPhone4,1": @"iPhone4S",//                          @"iPhone5,1": @"iPhone5",//                          @"iPhone5,2": @"iPhone5",//                          @"iPhone5,3": @"iPhone5C",//                          @"iPhone5,4": @"iPhone5C",//                          @"iPhone6,1": @"iPhone5S",//                          @"iPhone6,2": @"iPhone5S",//                          @"iPhone7,1": @"iPhone6_Plus",//                          @"iPhone7,2": @"iPhone6",//                          @"iPad1,1": @"iPad",//                          @"iPad2,1": @"iPad2",//                          @"iPad3,1": @"iPad3G",//                          @"iPad3,4": @"iPad4G",//                          @"iPad2,5": @"iPadMini",//                          @"iPad4,1": @"iPad5G_Air",//                          @"iPad4,2": @"iPad5G_Air",//                          @"iPad4,4": @"iPadMini2G",//                          @"iPad4,5": @"iPadMini2G"//                          };        free(machine);    return platform?platform:@"";}@end/* NSDictionary *dic = @{ @"i386": @"DeviceAppleSimulator", @"x86_64": @"DeviceAppleSimulator", @"iPod1,1": @"DeviceAppleiPodTouch", @"iPod2,1": @"DeviceAppleiPodTouch2G", @"iPod3,1": @"DeviceAppleiPodTouch3G", @"iPod4,1": @"DeviceAppleiPodTouch4G", @"iPhone1,1": @"DeviceAppleiPhone", @"iPhone1,2": @"DeviceAppleiPhone3G", @"iPhone2,1": @"DeviceAppleiPhone3GS", @"iPhone3,1": @"DeviceAppleiPhone4", @"iPhone3,3": @"DeviceAppleiPhone4", @"iPhone4,1": @"DeviceAppleiPhone4S", @"iPhone5,1": @"DeviceAppleiPhone5", @"iPhone5,2": @"DeviceAppleiPhone5", @"iPhone5,3": @"DeviceAppleiPhone5C", @"iPhone5,4": @"DeviceAppleiPhone5C", @"iPhone6,1": @"DeviceAppleiPhone5S", @"iPhone6,2": @"DeviceAppleiPhone5S", @"iPhone7,1": @"DeviceAppleiPhone6_Plus", @"iPhone7,2": @"DeviceAppleiPhone6", @"iPad1,1": @"DeviceAppleiPad", @"iPad2,1": @"DeviceAppleiPad2", @"iPad3,1": @"DeviceAppleiPad3G", @"iPad3,4": @"DeviceAppleiPad4G", @"iPad2,5": @"DeviceAppleiPadMini", @"iPad4,1": @"DeviceAppleiPad5G_Air", @"iPad4,2": @"DeviceAppleiPad5G_Air", @"iPad4,4": @"DeviceAppleiPadMini2G", @"iPad4,5": @"DeviceAppleiPadMini2G" };  */


1 0
原创粉丝点击