iOS获取设备信息(持续更新中...)

需要引入的头文件(全部):

<sys/socket.h>、<sys/sysctl.h>、<net/if.h>、<net/if_dl.h>、<mach/mach.h>、<mach/mach_host.h>、<sys/types.h>、<sys/param.h>、<sys/mount.h>、<mach/processor_info.h>、<sys/stat.h>、<sys/sockio.h>、<sys/ioctl.h>、<arpa/inet.h>、<CoreTelephony/CTTelephonyNetworkInfo.h>、<CoreTelephony/CTCarrier.h>、<AdSupport/AdSupport.h>

正文:

PS:枚举和宏定义在最后列出


#pragma mark -

#pragma mark -  获取手机型号(枚举)

+ (UIDeviceModel)deviceModelEnum

{

    return [[self alloc] deviceModelEnum];

}

- (UIDeviceModel)deviceModelEnum

{

    size_tsize;

    sysctlbyname("hw.machine",NULL, &size,NULL,0);

    char*answer =malloc(size);

    sysctlbyname("hw.machine", answer, &size,NULL,0);

    NSString *platform = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];

    free(answer);

    if([platformisEqualToString:@"iFPGA"])    returnUIDeviceIFPGA;

    if([platformisEqualToString:@"iPhone1,1"])    returnUIDeviceiPhone1G;

    if([platformisEqualToString:@"iPhone1,2"])    returnUIDeviceiPhone3G;

    if([platformhasPrefix:@"iPhone2"])    returnUIDeviceiPhone3GS;

    if([platformhasPrefix:@"iPhone3"])    returnUIDeviceiPhone4;

    if([platformhasPrefix:@"iPhone4"])    returnUIDeviceiPhone4S;

    if([platformisEqualToString:@"iPhone5,1"])    returnUIDeviceiPhone5;

    if([platformisEqualToString:@"iPhone5,2"])    returnUIDeviceiPhone5;

    if([platformisEqualToString:@"iPhone5,3"])    returnUIDeviceiPhone5C;

    if([platformisEqualToString:@"iPhone5,4"])    returnUIDeviceiPhone5C;

    if([platformisEqualToString:@"iPhone6,1"])    returnUIDeviceiPhone5S;

    if([platformisEqualToString:@"iPhone6,2"])    returnUIDeviceiPhone5S;

    if([platformisEqualToString:@"iPhone7,2"])    returnUIDeviceiPhone6;

    if([platformisEqualToString:@"iPhone7,1"])    returnUIDeviceiPhone6Plus;

    if([platformisEqualToString:@"iPhone8,1"])    returnUIDeviceiPhone6S;

    if([platformisEqualToString:@"iPhone8,2"])    returnUIDeviceiPhone6SPlus;

    if([platformisEqualToString:@"iPhone9,1"])    returnUIDeviceiPhone7;

    if([platformisEqualToString:@"iPhone9,2"])    returnUIDeviceiPhone7Plus;

    if([platformisEqualToString:@"iPhone9,3"])    returnUIDeviceiPhone7;

    if([platformisEqualToString:@"iPhone9,4"])    returnUIDeviceiPhone7Plus;

    if([platformisEqualToString:@"iPhone10,1"])  returnUIDeviceiPhone8;

    if([platformisEqualToString:@"iPhone10,4"])  returnUIDeviceiPhone8;

    if([platformisEqualToString:@"iPhone10,2"])  returnUIDeviceiPhone8Plus;

    if([platformisEqualToString:@"iPhone10,5"])  returnUIDeviceiPhone8Plus;

    if([platformisEqualToString:@"iPhone10,3"])  returnUIDeviceiPhoneX;

    if([platformisEqualToString:@"iPhone10,6"])  returnUIDeviceiPhoneX;

    if ([platform isEqualToString:@"i386"]) return UIDeviceiPhoneSimulator32;

    if ([platform isEqualToString:@"x86_64"])  return UIDeviceiPhoneSimulator64;

    if([platformhasPrefix:@"iPod1"])  returnUIDeviceiPod1G;

    if([platformhasPrefix:@"iPod2"])  returnUIDeviceiPod2G;

    if([platformhasPrefix:@"iPod3"])  returnUIDeviceiPod3G;

    if([platformhasPrefix:@"iPod4"])  returnUIDeviceiPod4G;

    if([platformhasPrefix:@"iPod5"])  returnUIDeviceiPod5G;

    if([platformhasPrefix:@"iPod7"])  returnUIDeviceiPod6G;

    if([platformisEqualToString:@"iPad1,1"])  returnUIDeviceiPad1G;

    if([platformisEqualToString:@"iPad2,1"])  returnUIDeviceiPad2G;

    if([platformisEqualToString:@"iPad2,2"])  returnUIDeviceiPad2G;

    if([platformisEqualToString:@"iPad2,3"])  returnUIDeviceiPad2G;

    if([platformisEqualToString:@"iPad2,4"])  returnUIDeviceiPad2G;

    if([platformisEqualToString:@"iPad3,1"])  returnUIDeviceiPad3G;

    if([platformisEqualToString:@"iPad3,2"])  returnUIDeviceiPad3G;

    if([platformisEqualToString:@"iPad3,3"])  returnUIDeviceiPad3G;

    if([platformisEqualToString:@"iPad3,4"])  returnUIDeviceiPad4G;

    if([platformisEqualToString:@"iPad3,5"])  returnUIDeviceiPad4G;

    if([platformisEqualToString:@"iPad3,6"])  returnUIDeviceiPad4G;

    if([platformisEqualToString:@"iPad4,1"])  returnUIDeviceiPadAir1;

    if([platformisEqualToString:@"iPad4,2"])  returnUIDeviceiPadAir1;

    if([platformisEqualToString:@"iPad4,3"])  returnUIDeviceiPadAir1;

    if([platformisEqualToString:@"iPad5,3"])  returnUIDeviceiPadAir2;

    if([platformisEqualToString:@"iPad5,4"])  returnUIDeviceiPadAir2;

    if([platformisEqualToString:@"iPad2,5"])  returnUIDeviceiPadmini1;

    if([platformisEqualToString:@"iPad2,6"])  returnUIDeviceiPadmini1;

    if([platformisEqualToString:@"iPad2,7"])  returnUIDeviceiPadmini1;

    if([platformisEqualToString:@"iPad4,4"])  returnUIDeviceiPadmini2;

    if([platformisEqualToString:@"iPad4,5"])  returnUIDeviceiPadmini2;

    if([platformisEqualToString:@"iPad4,6"])  returnUIDeviceiPadmini2;

    if([platformisEqualToString:@"iPad4,7"])  returnUIDeviceiPadmini3;

    if([platformisEqualToString:@"iPad4,8"])  returnUIDeviceiPadmini3;

    if([platformisEqualToString:@"iPad4,9"])  returnUIDeviceiPadmini3;

    if([platformisEqualToString:@"iPad5,1"])  returnUIDeviceiPadmini4;

    if([platformisEqualToString:@"iPad5,2"])  returnUIDeviceiPadmini4;

    if([platformhasPrefix:@"AppleTV2"])  returnUIDeviceAppleTV2;

    if([platformhasPrefix:@"AppleTV3"])  returnUIDeviceAppleTV3;

    if([platformhasPrefix:@"iPhone"])returnUIDeviceUnknowniPhone;

    if([platformhasPrefix:@"iPod"])  returnUIDeviceUnknowniPod;

    if([platformhasPrefix:@"iPad"])  returnUIDeviceUnknowniPad;

    if([platformhasPrefix:@"AppleTV"])    returnUIDeviceUnknownAppleTV;

    return UIDeviceUnknown;

}


#pragma mark -

#pragma mark - 获取设备名称

+ (NSString*)deviceName

{

    return [[UIDevice currentDevice] name];

}


#pragma mark -

#pragma mark - 获取手机型号(字符串)

+ (NSString*)deviceModelString {

    return [[self alloc] deviceModelString];

}

- (NSString*)deviceModelString {

    switch ([self deviceModelEnum]) {

        case UIDeviceUnknown:  return DEVICE_UNKNOWN;

        case UIDeviceSimulator:  return SIMULATOR_DEVICE;

        case UIDeviceSimulatoriPhone:  return IPHONE_SIMULATOR_DEVICE;

        case UIDeviceSimulatoriPad:  return IPAD_SIMULATOR_DEVICE;

        case UIDeviceSimulatorAppleTV:  return APPLETV_SIMULATOR_DEVICE;

        case UIDeviceiPhone1G:  return IPHONE_1G_DEVICE;

        case UIDeviceiPhone3G:  return IPHONE_3G_DEVICE;

        case UIDeviceiPhone3GS:  return IPHONE_3GS_DEVICE;

        case UIDeviceiPhone4:  return IPHONE_4_DEVICE;

        case UIDeviceiPhone4S:  return IPHONE_4S_DEVICE;

        case UIDeviceiPhone5:  return IPHONE_5_DEVICE;

        case UIDeviceiPhone5C:  return IPHONE_5C_DEVICE;

        case UIDeviceiPhone5S:  return IPHONE_5S_DEVICE;

        case UIDeviceiPhone6:  return IPHONE_6_DEVICE;

        case UIDeviceiPhone6Plus:  return IPHONE_6Plus_DEVICE;

        case UIDeviceiPhone6S:  return IPHONE_6S_DEVICE;

        case UIDeviceiPhone6SPlus:  return IPHONE_6SPlus_DEVICE;

        case UIDeviceiPhone7:  return IPHONE_7_DEVICE;

        case UIDeviceiPhone7Plus:  return IPHONE_7Plus_DEVICE;

        case UIDeviceiPhone8:  return IPHONE_8_DEVICE;

        case UIDeviceiPhone8Plus:  return IPHONE_8Plus_DEVICE;

        case UIDeviceiPhoneX:  return IPHONE_X_DEVICE;

        case UIDeviceiPhoneSimulator32:  return IPHONE_SIMULATOR32_DEVICE;

        case UIDeviceiPhoneSimulator64:  return IPHONE_SIMULATOR64_DEVICE;

        case UIDeviceiPod1G:  return IPOD_1G_DEVICE;

        case UIDeviceiPod2G:  return IPOD_2G_DEVICE;

        case UIDeviceiPod3G:  return IPOD_3G_DEVICE;

        case UIDeviceiPod4G:  return IPOD_4G_DEVICE;

        case UIDeviceiPod5G:  return IPOD_5G_DEVICE;

        case UIDeviceiPod6G:  return IPOD_6G_DEVICE;

        case UIDeviceiPad1G:  return IPAD_1G_DEVICE;

        case UIDeviceiPad2G:  return IPAD_2G_DEVICE;

        case UIDeviceiPad3G:  return IPAD_3G_DEVICE;

        case UIDeviceiPad4G:  return IPAD_4G_DEVICE;

        case UIDeviceiPadAir1:  return IPADAIR_1G_DEVICE;

        case UIDeviceiPadAir2:  return IPADAIR_2G_DEVICE;

        case UIDeviceiPadmini1:  return IPADMINI_1G_DEVICE;

        case UIDeviceiPadmini2:  return IPADMINI_2G_DEVICE;

        case UIDeviceiPadmini3:  return IPADMINI_3G_DEVICE;

        case UIDeviceiPadmini4:  return IPADMINI_4G_DEVICE;

        case UIDeviceAppleTV2:  return APPLETV_2G_DEVICE;

        case UIDeviceAppleTV3:  return APPLETV_3G_DEVICE;

        case UIDeviceAppleTV4:  return APPLETV_4G_DEVICE;

        case UIDeviceUnknowniPhone:  return IPHONE_UNKNOWN_DEVICE;

        case UIDeviceUnknowniPod:  return IPOD_UNKNOWN_DEVICE;

        case UIDeviceUnknowniPad:  return IPAD_UNKNOWN_DEVICE;

        case UIDeviceUnknownAppleTV:  return APPLETV_UNKNOWN_DEVICE;

        caseUIDeviceIFPGA:  returnIFPGA_DEVICE;

        default: return DEVICE_UNKNOWN;

    }

}


#pragma mark -

#pragma mark - 获取设备UUID

+ (NSString*)deviceUUID

{

    //  设备UUID有可能带有 '-' 符号

    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];

}


#pragma mark -

#pragma mark - 获取系统名称

+ (NSString*)deviceSystemName

{

    return [[UIDevice currentDevice] systemName];

}


#pragma mark -

#pragma mark - 获取系统版本

+ (NSString*)deviceSystemVersion

{

    return [[UIDevice currentDevice] systemVersion];

}


 #pragma mark -

 #pragma mark - 获取设备类别

+ (NSString*)deviceModel

{

    return [[UIDevice currentDevice] model];

}


 #pragma mark -

 #pragma mark - 获取设备本地化信息

+ (NSString*)deviceLocalInfo

{

    return [[UIDevice currentDevice] localizedModel];

}


#pragma mark -

#pragma mark - 获取App相关信息

+ (NSDictionary*)appAboutInfo

{

    return [[NSBundle mainBundle] infoDictionary];;

}


#pragma mark -

#pragma mark - 获取App应用名称

+ (NSString*)appName

{

    return [[self appAboutInfo] objectForKey:@"CFBundleName"];

}


#pragma mark -

#pragma mark - 获取App应用版本号

+ (NSString*)appVersion

{

    return [[self appAboutInfo] objectForKey:@"CFBundleShortVersionString"];

}


#pragma mark -

#pragma mark - 获取App应用的build版本号

+ (NSString*)appBuildVersion

{

    return [[self appAboutInfo] objectForKey:@"CFBundleVersion"];

}


#pragma mark -

#pragma mark - 获取设备选中的国家

+ (NSString*)deviceSelectCountry

{

    NSLocale *locale = [NSLocale currentLocale];

    return [locale localeIdentifier];

}


#pragma mark -

#pragma mark - 获取运行商的名称

+ (NSString*)deviceNetName

{

    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];

    CTCarrier *carrier = [info subscriberCellularProvider];

    return [NSString stringWithFormat:@"%@",[carrier carrierName]];

}


#pragma mark -

#pragma mark - iOS7以后获取当前网络类型

+ (NSString*)deviceConnectType

{

    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];

    return [[NSString alloc] initWithFormat:@"%@",info.currentRadioAccessTechnology];

}


#pragma mark -

#pragma mark - 判断设备是否越狱

+ (BOOL)deviceJailBreakStatus

{

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]) {

        returnYES;

    }

    return NO;

}


#pragma mark -

#pragma mark - iOS6以上获取设备电池电量等级

+ (int)deviceBatteryLevel

{

    UIApplication *app = [UIApplication sharedApplication];

    if (app.applicationState == UIApplicationStateActive || app.applicationState==UIApplicationStateInactive) {

        Ivarivar=  class_getInstanceVariable([app class],"_statusBar");

        idstatus  =object_getIvar(app, ivar);

        for(idaviewin[statussubviews]) {

            intbatteryLevel =0;

            for(idbviewin[aviewsubviews]) {

                if ([NSStringFromClass([bview class]) caseInsensitiveCompare:@"UIStatusBarBatteryItemView"] == NSOrderedSame &&

                    [[[UIDevice currentDevice] systemVersion] floatValue] >=6.0) {

                    Ivarivar=  class_getInstanceVariable([bviewclass],"_capacity");

                    if(ivar) {

                        batteryLevel = ((int(*)(id,Ivar))object_getIvar)(bview, ivar);

                        if(batteryLevel >0&& batteryLevel <=100) {

                            returnbatteryLevel;

                        }else{

                            return0;

                        }

                    }

                }

            }

        }

    }

    return 0;

}


#pragma mark -

#pragma mark - 获取设备CPU型号

+ (NSString*)deviceCPUType

{

    switch ([self deviceModelEnum]) {

        case UIDeviceiPhone3G: return IPHONE_3G_CPUTYPE;

        case UIDeviceiPhone3GS: return IPHONE_3GS_CPUTYPE;

        case UIDeviceiPhone4: return IPHONE_4_CPUTYPE;

        case UIDeviceiPhone4S: return IPHONE_4S_CPUTYPE;

        case UIDeviceiPod4G: return IPOD_4G_CPUTYPE;

        case UIDeviceiPhone5: return IPHONE_5_CPUTYPE;

        case UIDeviceiPhone5C: return IPHONE_5C_CPUTYPE;

        case UIDeviceiPhone5S: return IPHONE_5S_CPUTYPE;

        case UIDeviceiPhone6:return IPHONE_6_CPUTYPE;

        case UIDeviceiPhone6Plus: return IPHONE_6Plus_CPUTYPE;

        case UIDeviceiPhone6S: return IPHONE_6S_CPUTYPE;

        case UIDeviceiPhone6SPlus: return IPHONE_6SPlus_CPUTYPE;

        case UIDeviceiPhone7:return IPHONE_7_CPUTYPE;

        case UIDeviceiPhone7Plus: return IPHONE_7Plus_CPUTYPE;

        case UIDeviceiPhone8: return IPHONE_8_CPUTYPE;

        case UIDeviceiPhone8Plus: return IPHONE_8Plus_CPUTYPE;

        case UIDeviceiPhoneX: return IPHONE_X_CPUTYPE;

        default: return IOS_CPUTYPE_UNKNOWN;

    }

}


#pragma mark -

#pragma mark - 获取CPU频率

+ (NSString*)deviceCPUFrequency

{

    switch ([self deviceModelEnum]) {

        case UIDeviceiPhone3G: return IPHONE_3G_CPUFREQUENCY;

        case UIDeviceiPhone3GS: return IPHONE_3GS_CPUFREQUENCY;

        case UIDeviceiPhone4: return IPHONE_4_CPUFREQUENCY;

        case UIDeviceiPhone4S: return IPHONE_4S_CPUFREQUENCY;

        case UIDeviceiPhone5C: return IPHONE_5C_CPUFREQEENCY;

        case UIDeviceiPhone5: return IPHONE_5_CPUFREQEENCY;

        case UIDeviceiPhone5S: return IPHONE_5S_CPUFREQEENCY;

        case UIDeviceiPhone6:return IPHONE_6Plus_CPUFREQEENCY;

        case UIDeviceiPhone6Plus:return IPHONE_6Plus_CPUFREQEENCY;

        case UIDeviceiPhone6S:return IPHONE_6SPlus_CPUTYPE;

        case UIDeviceiPhone6SPlus:return IPHONE_6SPlus_CPUTYPE;

        case UIDeviceiPhone7:return IPHONE_7_CPUFREQEENCY;

        case UIDeviceiPhone7Plus:return IPHONE_7Plus_CPUFREQEENCY;

        case UIDeviceiPod4G: return IPOD_4G_CPUFREQUENCY;

        default: return IOS_CPUFREQUENCY_UNKNOWN;

    }

}


#pragma mark -

#pragma mark - 获取设备CPU内核数

+ (NSUInteger)deviceCPUCoreCount

{

    size_tsize =sizeof(int);

    intresults;

    intmib[2] = {CTL_HW,HW_NCPU};

    sysctl(mib,2, &results, &size,NULL,0);

    return(NSUInteger) results;

}


#pragma mark -

#pragma mark - 获取设备CPU使用率

+ (float)deviceCPUUsage

{

    kern_return_t kr;

    task_info_data_t tinfo;

    mach_msg_type_number_t task_info_count;

    task_info_count =TASK_INFO_MAX;

    kr =task_info(mach_task_self(),TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count);

    if(kr !=KERN_SUCCESS) {

        return-1;

    }

    task_basic_info_t      basic_info;

    thread_array_t        thread_list;

    mach_msg_type_number_t thread_count;

    thread_info_data_t    thinfo;

    mach_msg_type_number_tthread_info_count;

    thread_basic_info_t basic_info_th;

    uint32_tstat_thread =0;// Mach threads

    basic_info = (task_basic_info_t)tinfo;

    kr =task_threads(mach_task_self(), &thread_list, &thread_count);

    if(kr !=KERN_SUCCESS) {

        return-1;

    }

    if(thread_count >0)

        stat_thread += thread_count;

    longtot_sec =0;

    longtot_usec =0;

    floattot_cpu =0;

    intj;

    for(j =0; j < thread_count; j++) {

        thread_info_count =THREAD_INFO_MAX;

        kr =thread_info(thread_list[j],THREAD_BASIC_INFO,(thread_info_t)thinfo, &thread_info_count);

        if(kr !=KERN_SUCCESS) {

            return-1;

        }

        basic_info_th = (thread_basic_info_t)thinfo;

        if(!(basic_info_th->flags&TH_FLAGS_IDLE)) {

            tot_sec = tot_sec + basic_info_th->user_time.seconds+ basic_info_th->system_time.seconds;

            tot_usec = tot_usec + basic_info_th->user_time.microseconds+ basic_info_th->system_time.microseconds;

            tot_cpu = tot_cpu + basic_info_th->cpu_usage/ (float)TH_USAGE_SCALE*100.0;

        }

    }

    kr =vm_deallocate(mach_task_self(), (vm_offset_t)thread_list, thread_count *sizeof(thread_t));

    assert(kr == KERN_SUCCESS);

    returntot_cpu;

}


#pragma mark -

#pragma mark - 获取设备内存总量,返回字节数

+ (NSUInteger)deviceMemoryBytes

{

    size_tsize =sizeof(int);

    intresults;

    intmib[2] = {CTL_HW,HW_PHYSMEM};

    sysctl(mib,2, &results, &size,NULL,0);

    return(NSUInteger) results;

}


#pragma mark -

#pragma mark - 获取设备可用内存量,返回字节数

+ (NSUInteger)deviceFreeMemoeryBytes

{

    mach_port_t          host_port =mach_host_self();

    mach_msg_type_number_t  host_size =sizeof(vm_statistics_data_t) / sizeof(integer_t);

    vm_size_t              pagesize;

    vm_statistics_data_t    vm_stat;

    host_page_size(host_port, &pagesize);

    if(host_statistics(host_port,HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) !=KERN_SUCCESS)NSLog(@"Failed to fetch vm statistics");

    natural_t  mem_free =vm_stat.free_count * pagesize;

    returnmem_free;

}


#pragma mark -

#pragma mark - 获取手机硬盘空闲空间,返回的是字节数

+ (longlong)deviceFreeDiskSpaceBytes

{

    structstatfsbuf;

    longlongfreespace;

    freespace =0;

    if(statfs("/private/var", &buf) >=0){

        freespace = (longlong)buf.f_bsize* buf.f_bfree;

    }

    returnfreespace;

}


#pragma mark -

#pragma mark - 获取手机硬盘总空间,返回的是字节数

+ (longlong)deviceDiskSpaceBytes

{

    structstatfsbuf;

    longlongtotalspace;

    totalspace =0;

    if(statfs("/private/var", &buf) >=0){

        totalspace = (longlong)buf.f_bsize* buf.f_blocks;

    }

    returntotalspace;

}


#pragma mark -

#pragma mark - 判断设备是否支持蓝牙

+ (BOOL)deviceBluetoothStatus

{

    switch ([self deviceModelEnum]) {

        case UIDeviceiPhone3G:  return YES;

        case UIDeviceiPhone3GS: return YES;

        case UIDeviceiPhone4:  return YES;

        case UIDeviceiPhone4S:  return YES;

        case UIDeviceiPhone5:  return YES;

        case UIDeviceiPhone5C:  return YES;

        case UIDeviceiPhone5S:  return YES;

        case UIDeviceiPhone6:  return YES;

        case UIDeviceiPhone6Plus:  return YES;

        case UIDeviceiPhone6S:  return YES;

        case UIDeviceiPhone6SPlus:  return YES;

        case UIDeviceiPhone7:  return YES;

        case UIDeviceiPhone7Plus:  return YES;

        case UIDeviceiPhone8:  return YES;

        case UIDeviceiPhone8Plus:  return YES;

        case UIDeviceiPhoneX:  return YES;

        caseUIDeviceiPod3G:    returnYES;

        caseUIDeviceiPod4G:    returnYES;

        caseUIDeviceiPod5G:    returnYES;

        caseUIDeviceiPod6G:    returnYES;

        caseUIDeviceiPad1G:  returnYES;

        caseUIDeviceiPad2G:  returnYES;

        caseUIDeviceiPad3G:  returnYES;

        caseUIDeviceiPad4G:  returnYES;

        case UIDeviceiPadAir1: return YES;

        case UIDeviceiPadAir2: return YES;

        case UIDeviceiPadmini1:    return YES;

        case UIDeviceiPadmini2:    return YES;

        case UIDeviceiPadmini3:    return YES;

        case UIDeviceiPadmini4:    return YES;

        default: return NO;

    }

}


#pragma mark -

#pragma mark - 获取当前任务所占内存,返回MB

+ (double)deviceCurrentUseMemoery

{

    task_basic_info_data_t taskInfo;

    mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;

    kern_return_t kernReturn = task_info(mach_task_self(),

                                         TASK_BASIC_INFO,

                                         (task_info_t)&taskInfo,

                                         &infoCount);

    if(kernReturn !=KERN_SUCCESS

        ) {

        return NSNotFound;

    }


    returntaskInfo.resident_size/1024.0/1024.0;

}


#pragma mark -

#pragma mark - 获取设备广告位标识符

+ (NSString*)deviceIDFA

{

    return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

}


#pragma mark -

#pragma mark - 获取设备MAC地址

+ (NSString*)deviceMacAddr

{

    intmib[6];

    size_tlen;

    char*buf;

    unsigned char *ptr;

    structif_msghdr*ifm;

    struct sockaddr_dl *sdl;

    mib[0] =CTL_NET;

    mib[1] =AF_ROUTE;

    mib[2] =0;

    mib[3] =AF_LINK;

    mib[4] = NET_RT_IFLIST;

    if((mib[5] =if_nametoindex("en0")) ==0) {

        printf("Error: if_nametoindex error/n");

        return NULL;

    }

    if(sysctl(mib,6,NULL, &len,NULL,0) <0) {

        printf("Error: sysctl, take 1/n");

        return NULL;

    }

    if((buf =malloc(len)) ==NULL) {

        printf("Could not allocate memory. error!/n");

        return NULL;

    }

    if(sysctl(mib,6, buf, &len,NULL,0) <0) {

        printf("Error: sysctl, take 2");

        return NULL;

    }

    ifm = (structif_msghdr*)buf;

    sdl = (structsockaddr_dl*)(ifm +1);

    ptr = (unsignedchar*)LLADDR(sdl);

    NSString*outstring = [NSStringstringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];

    free(buf);

    return[outstringuppercaseString];

}


#pragma mark -

#pragma mark - 获取设备IP地址

+ (NSString*)deviceIPAddr

{

    intsockfd =socket(AF_INET,SOCK_DGRAM,0);

    NSMutableArray *ips = [NSMutableArray array];

    intBUFFERSIZE =4096;

    structifconfifc;

    charbuffer[BUFFERSIZE], *ptr, lastname[IFNAMSIZ], *cptr;

    structifreq*ifr, ifrcopy;

    ifc.ifc_len= BUFFERSIZE;

    ifc.ifc_buf= buffer;

    if(ioctl(sockfd,SIOCGIFCONF, &ifc) >=0){

        for(ptr = buffer; ptr < buffer + ifc.ifc_len; ){

            ifr = (structifreq*)ptr;

            intlen =sizeof(structsockaddr);

            if(ifr->ifr_addr.sa_len> len) {

                len = ifr->ifr_addr.sa_len;

            }

            ptr +=sizeof(ifr->ifr_name) + len;

            if(ifr->ifr_addr.sa_family!=AF_INET)continue;

            if((cptr = (char*)strchr(ifr->ifr_name,':')) !=NULL) *cptr =0;

            if(strncmp(lastname, ifr->ifr_name,IFNAMSIZ) ==0)continue;

            memcpy(lastname, ifr->ifr_name,IFNAMSIZ);

            ifrcopy = *ifr;

            ioctl(sockfd,SIOCGIFFLAGS, &ifrcopy);

            if((ifrcopy.ifr_flags&IFF_UP) ==0)continue;

            NSString *ip = [NSString  stringWithFormat:@"%s", inet_ntoa(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr)];

            [ipsaddObject:ip];

        }

    }

    close(sockfd);

    NSString*deviceIP =@"";

    for(inti=0; i < ips.count; i++) {

        if(ips.count>0) {

            deviceIP = [NSString stringWithFormat:@"%@",ips.lastObject];

        }

    }

    returndeviceIP;

}


/** === 设备中文名称 === */ 

#define DEVICE_UNKNOWN  @"Unknown Device"

 #define SIMULATOR_DEVICE @"Simulator" 

#define IPHONE_SIMULATOR_DEVICE @"iPhone Simulator" 

#define IPAD_SIMULATOR_DEVICE @"iPad Simulator" 

#define APPLETV_SIMULATOR_DEVICE @"AppleTV Simulator" 

#define IPHONE_1G_DEVICE    @"iPhone 1G" 

#define IPHONE_3G_DEVICE    @"iPhone 3G" 

#define IPHONE_3GS_DEVICE   @"iPhone 3GS" 

#define IPHONE_4_DEVICE @"iPhone 4"

 #define IPHONE_4S_DEVICE    @"iPhone 4S" 

#define IPHONE_5_DEVICE @"iPhone 5" 

#define IPHONE_5C_DEVICE    @"iPhone 5C" 

#define IPHONE_5S_DEVICE    @"iPhone 5S" 

#define IPHONE_6_DEVICE @"iPhone 6" 

#define IPHONE_6Plus_DEVICE @"iPhone 6Plus" 

#define IPHONE_6S_DEVICE    @"iPhone 6S" 

#define IPHONE_6SPlus_DEVICE    @"iPhone 6SPlus"

 #define IPHONE_7_DEVICE @"iPhone 7" 

#define IPHONE_7Plus_DEVICE @"iPhone 7Plus" 

#define IPHONE_8_DEVICE @"iPhone 8" 

#define IPHONE_8Plus_DEVICE @"iPhone 8Plus" 

#define IPHONE_X_DEVICE @"iPhone X" 

#define IPHONE_SIMULATOR32_DEVICE  @"iPhone Simulator32"

 #define IPHONE_SIMULATOR64_DEVICE  @"iPhone Simulator64"

 #define IPOD_1G_DEVICE  @"iPod touch 1G" 

#define IPOD_2G_DEVICE  @"iPod touch 2G" 

#define IPOD_3G_DEVICE  @"iPod touch 3G" 

#define IPOD_4G_DEVICE  @"iPod touch 4G" 

#define IPOD_5G_DEVICE  @"iPod Touch 5G" 

#define IPOD_6G_DEVICE  @"iPod Touch 6G"

 #define IPAD_1G_DEVICE  @"iPad 1G" 

#define IPAD_2G_DEVICE  @"iPad 2G" 

#define IPAD_3G_DEVICE  @"iPad 3G" 

#define IPAD_4G_DEVICE  @"iPad 4G"

 #define IPADAIR_1G_DEVICE   @"iPadAir 1G" 

#define IPADAIR_2G_DEVICE   @"iPadAir 2G" 

#define IPADMINI_1G_DEVICE  @"iPadMini 1G" 

#define IPADMINI_2G_DEVICE  @"iPadMini 2G" 

#define IPADMINI_3G_DEVICE  @"iPadMini 3G" 

#define IPADMINI_4G_DEVICE  @"iPadMini 4G" 

#define APPLETV_2G_DEVICE   @"Apple TV 2G" 

#define APPLETV_3G_DEVICE   @"Apple TV 3G" 

#define APPLETV_4G_DEVICE   @"Apple TV 4G" 

#define IPHONE_UNKNOWN_DEVICE @"Unknown iPhone" 

#define IPOD_UNKNOWN_DEVICE @"Unknown iPod" 

#define IPAD_UNKNOWN_DEVICE @"Unknown iPad" 

#define APPLETV_UNKNOWN_DEVICE  @"Unknown Apple TV" 

#define IFPGA_DEVICE    @"iFPGA" 

 /** === iPhone 3G以后各代的CPU型号和频率 === */ 

#define IPHONE_3G_CPUTYPE   @"ARM11" 

#define IPHONE_3G_CPUFREQUENCY  @"412MHz" 

#define IPHONE_3GS_CPUTYPE  @"ARM Cortex A8" 

#define IPHONE_3GS_CPUFREQUENCY @"600MHz" 

#define IPHONE_4_CPUTYPE    @"Apple A4" 

#define IPHONE_4_CPUFREQUENCY   @"1GMHz" 

#define IPHONE_4S_CPUTYPE   @"Apple A5 Double Core" 

#define IPHONE_4S_CPUFREQUENCY  @"800MHz" 

#define IPHONE_5_CPUTYPE    @"Apple A6" 

#define IPHONE_5_CPUFREQEENCY   @"1066MHz"

 #define IPHONE_5C_CPUTYPE   @"Apple A6"

 #define IPHONE_5C_CPUFREQEENCY  @"1GHz" 

#define IPHONE_5S_CPUTYPE   @"Apple A7" 

#define IPHONE_5S_CPUFREQEENCY  @"1228MHz" 

#define IPHONE_6_CPUTYPE    @"Apple A8" 

#define IPHONE_6_CPUFREQEENCY   @"1.4GHz" 

#define IPHONE_6Plus_CPUTYPE    @"Apple A8" 

#define IPHONE_6Plus_CPUFREQEENCY   @"1.4GHz"

 #define IPHONE_6S_CPUTYPE   @"Apple A9" 

#define IPHONE_6S_CPUFREQEENCY  @"1.8GHz" 

#define IPHONE_6SPlus_CPUTYPE   @"Apple A9" 

#define IPHONE_6SPlus_CPUFREQEENCY  @"1.8GHz" 

#define IPHONE_7_CPUTYPE    @"Apple A10" 

#define IPHONE_7_CPUFREQEENCY   @"2.4GHz"

 #define IPHONE_7Plus_CPUTYPE    @"Apple A10"

 #define IPHONE_7Plus_CPUFREQEENCY   @"2.4GHz" 

#define IPHONE_8_CPUTYPE    @"Apple A11" 

#define IPHONE_8_CPUFREQEENCY   @"2.4GHz"

 #define IPHONE_8Plus_CPUTYPE    @"Apple A11" 

#define IPHONE_8Plus_CPUFREQEENCY   @"2.4GHz" 

#define IPHONE_X_CPUTYPE    @"Apple A11" 

#define IPHONE_X_CPUFREQEENCY   @"2.4GHz" 

 /** === iPod 4G的CPU型号和频率 === */ 

#define IPOD_4G_CPUTYPE @"Apple A4" 

#define IPOD_4G_CPUFREQUENCY    @"800MHz"

 /** === 未知的CPU型号和频率 === */ 

#define IOS_CPUTYPE_UNKNOWN @"Unknown CPU type" 

#define IOS_CPUFREQUENCY_UNKNOWN    @"Unknown CPU frequency" 


 typedef NS_ENUM(NSInteger,UIDeviceModel) {    

UIDeviceUnknown,   //  未知设备型号    

UIDeviceSimulator,  //  模拟器    

UIDeviceSimulatoriPhone,    // iPhone模拟器   

 UIDeviceSimulatoriPad,  //  iPad模拟器   

 UIDeviceSimulatorAppleTV,   //  AppleTV模拟器   

 UIDeviceiPhone1G,   //  1代iPhone    

UIDeviceiPhone3G,   //  3代iPhone    

UIDeviceiPhone3GS,  //  iPhone 3GS    

UIDeviceiPhone4,    //  iPhone 4    

UIDeviceiPhone4S,   //  iPhone 4s    

UIDeviceiPhone5,    //  iPhone 5    

UIDeviceiPhone5C,   //  iPhone 5c    

UIDeviceiPhone5S,   //  iPhone 5s    

UIDeviceiPhone6,    //  iPhone 6    

UIDeviceiPhone6Plus,    //  iPhone 6Plus    

UIDeviceiPhone6S,   //  iPhone 6s    

UIDeviceiPhone6SPlus,   //  iPhone 6sPlus    

UIDeviceiPhone7,    //  iPhone 7    

UIDeviceiPhone7Plus,    //  iPhone 7Plus    

UIDeviceiPhone8,    //  iPhone 8    

UIDeviceiPhone8Plus,    //  iPhone 8Plus    

UIDeviceiPhoneX,    //  iPhone X    

UIDeviceiPhoneSimulator32,  //  32位iPhone模拟器    

UIDeviceiPhoneSimulator64,  //  64位iPhone模拟器    

UIDeviceiPod1G, //  1代iPod    

UIDeviceiPod2G, //  2代iPod   

 UIDeviceiPod3G, //  3代iPod   

 UIDeviceiPod4G, //  4代iPod   

 UIDeviceiPod5G, //  5代iPod    

UIDeviceiPod6G, //  6代iPod    

UIDeviceiPad1G,  //  1代iPad   

 UIDeviceiPad2G,  //  2代iPad    

UIDeviceiPad3G,  //  3代iPad  

  UIDeviceiPad4G,  //  4代iPad    

UIDeviceiPadAir1,  //  1代iPadAir    

UIDeviceiPadAir2,  //  2代iPadAir    

UIDeviceiPadmini1,  //  1代iPadMini    

UIDeviceiPadmini2,  //  2代iPadMini   

 UIDeviceiPadmini3,  //  3代iPadMini    

UIDeviceiPadmini4,  //  4代iPadMini    

UIDeviceAppleTV2,  //  2代AppleTV    

UIDeviceAppleTV3,  //  3代AppleTV    

UIDeviceAppleTV4,  //  4代AppleTV   

 UIDeviceUnknowniPhone,    //  未知类型的iPhone  

  UIDeviceUnknowniPod,      //  未知类型的iPod    

UIDeviceUnknowniPad,    //  未知类型的iPad  

  UIDeviceUnknownAppleTV,   //  未知类型的AppleTV   

 UIDeviceIFPGA 

};



1. 目前获取到的mac地址都是02:00:00:00:00:00,苹果现在限制比较严,整理好后会放出...

2. 获取设备信息方法有很多种,这里只列出本人常用的,有其他更好的欢迎指出;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,393评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,790评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,391评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,703评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,613评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,003评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,507评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,158评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,300评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,256评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,274评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,984评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,569评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,662评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,899评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,268评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,840评论 2 339

推荐阅读更多精彩内容