当前位置:   article > 正文

获取苹果设备和系统信息(更新至iPhone X)_plink.exe获取苹果设备信息systemversion.plist

plink.exe获取苹果设备信息systemversion.plist

1.获得设备型号

  1. #import <sys/utsname.h>
  2. + (NSString *)getCurrentDeviceModel
  3. {
  4. struct utsname systemInfo;
  5. uname(&systemInfo);
  6. NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
  7. // iPhone
  8. if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone2G";
  9. if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone3G";
  10. if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone3GS";
  11. if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone4";
  12. if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone4";
  13. if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone4";
  14. if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone4S";
  15. if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone5";
  16. if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone5";
  17. if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone5c";
  18. if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone5c";
  19. if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone5s";
  20. if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone5s";
  21. if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone6";
  22. if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus";
  23. if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
  24. if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone6sPlus";
  25. if ([platform isEqualToString:@"iPhone8,3"]) return @"iPhoneSE";
  26. if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhoneSE";
  27. if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone7";
  28. if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone7Plus";
  29. if ([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
  30. if ([platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
  31. if ([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
  32. if ([platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
  33. if ([platform isEqualToString:@"iPhone10,3"]) return @"iPhone X";
  34. if ([platform isEqualToString:@"iPhone10,6"]) return @"iPhone X";
  35. //iPod Touch
  36. if ([platform isEqualToString:@"iPod1,1"]) return @"iPodTouch";
  37. if ([platform isEqualToString:@"iPod2,1"]) return @"iPodTouch2G";
  38. if ([platform isEqualToString:@"iPod3,1"]) return @"iPodTouch3G";
  39. if ([platform isEqualToString:@"iPod4,1"]) return @"iPodTouch4G";
  40. if ([platform isEqualToString:@"iPod5,1"]) return @"iPodTouch5G";
  41. if ([platform isEqualToString:@"iPod7,1"]) return @"iPodTouch6G";
  42. //iPad
  43. if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
  44. if ([platform isEqualToString:@"iPad2,1"]) return @"iPad2";
  45. if ([platform isEqualToString:@"iPad2,2"]) return @"iPad2";
  46. if ([platform isEqualToString:@"iPad2,3"]) return @"iPad2";
  47. if ([platform isEqualToString:@"iPad2,4"]) return @"iPad2";
  48. if ([platform isEqualToString:@"iPad3,1"]) return @"iPad3";
  49. if ([platform isEqualToString:@"iPad3,2"]) return @"iPad3";
  50. if ([platform isEqualToString:@"iPad3,3"]) return @"iPad3";
  51. if ([platform isEqualToString:@"iPad3,4"]) return @"iPad4";
  52. if ([platform isEqualToString:@"iPad3,5"]) return @"iPad4";
  53. if ([platform isEqualToString:@"iPad3,6"]) return @"iPad4";
  54. //iPad Air
  55. if ([platform isEqualToString:@"iPad4,1"]) return @"iPadAir";
  56. if ([platform isEqualToString:@"iPad4,2"]) return @"iPadAir";
  57. if ([platform isEqualToString:@"iPad4,3"]) return @"iPadAir";
  58. if ([platform isEqualToString:@"iPad5,3"]) return @"iPadAir2";
  59. if ([platform isEqualToString:@"iPad5,4"]) return @"iPadAir2";
  60. //iPad mini
  61. if ([platform isEqualToString:@"iPad2,5"]) return @"iPadmini1G";
  62. if ([platform isEqualToString:@"iPad2,6"]) return @"iPadmini1G";
  63. if ([platform isEqualToString:@"iPad2,7"]) return @"iPadmini1G";
  64. if ([platform isEqualToString:@"iPad4,4"]) return @"iPadmini2";
  65. if ([platform isEqualToString:@"iPad4,5"]) return @"iPadmini2";
  66. if ([platform isEqualToString:@"iPad4,6"]) return @"iPadmini2";
  67. if ([platform isEqualToString:@"iPad4,7"]) return @"iPadmini3";
  68. if ([platform isEqualToString:@"iPad4,8"]) return @"iPadmini3";
  69. if ([platform isEqualToString:@"iPad4,9"]) return @"iPadmini3";
  70. if ([platform isEqualToString:@"iPad5,1"]) return @"iPadmini4";
  71. if ([platform isEqualToString:@"iPad5,2"]) return @"iPadmini4";
  72. if ([platform isEqualToString:@"i386"]) return @"iPhoneSimulator";
  73. if ([platform isEqualToString:@"x86_64"]) return @"iPhoneSimulator";
  74. return platform;
  75. }

2.获取电池电量(一般用百分数表示,大家自行处理就好)

  1. -(CGFloat)getBatteryQuantity
  2. {
  3. return [[UIDevice currentDevice] batteryLevel];
  4. }

3.获取电池状态(UIDeviceBatteryState为枚举类型)

  1. -(UIDeviceBatteryState)getBatteryStauts
  2. {
  3. return [UIDevice currentDevice].batteryState;
  4. }

4.获取总内存大小

  1. -(long long)getTotalMemorySize
  2. {
  3. return [NSProcessInfo processInfo].physicalMemory;
  4. }

5.获取当前可用内存

  1. -(long long)getAvailableMemorySize
  2. {
  3. vm_statistics_data_t vmStats;
  4. mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
  5. kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
  6. if (kernReturn != KERN_SUCCESS)
  7. {
  8. return NSNotFound;
  9. }
  10. return ((vm_page_size * vmStats.free_count + vm_page_size * vmStats.inactive_count));
  11. }

6.获取已使用内存

  1. - (double)getUsedMemory
  2. {
  3. task_basic_info_data_t taskInfo;
  4. mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
  5. kern_return_t kernReturn = task_info(mach_task_self(),
  6. TASK_BASIC_INFO,
  7. (task_info_t)&taskInfo,
  8. &infoCount);
  9. if (kernReturn != KERN_SUCCESS
  10. ) {
  11. return NSNotFound;
  12. }
  13. return taskInfo.resident_size;
  14. }

7.获取总磁盘容量

  1. #include <sys mount.h="">
  2. -(long long)getTotalDiskSize
  3. {
  4. struct statfs buf;
  5. unsigned long long freeSpace = -1;
  6. if (statfs("/var", &buf) >= 0)
  7. {
  8. freeSpace = (unsigned long long)(buf.f_bsize * buf.f_blocks);
  9. }
  10. return freeSpace;
  11. }

8.获取可用磁盘容量

  1. -(long long)getAvailableDiskSize
  2. {
  3. struct statfs buf;
  4. unsigned long long freeSpace = -1;
  5. if (statfs("/var", &buf) >= 0)
  6. {
  7. freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
  8. }
  9. return freeSpace;
  10. }

9.容量转换

  1. -(NSString *)fileSizeToString:(unsigned long long)fileSize
  2. {
  3. NSInteger KB = 1024;
  4. NSInteger MB = KB*KB;
  5. NSInteger GB = MB*KB;
  6. if (fileSize < 10) {
  7. return @"0 B";
  8. }else if (fileSize < KB) {
  9. return @"< 1 KB";
  10. }else if (fileSize < MB) {
  11. return [NSString stringWithFormat:@"%.1f KB",((CGFloat)fileSize)/KB];
  12. }else if (fileSize < GB) {
  13. return [NSString stringWithFormat:@"%.1f MB",((CGFloat)fileSize)/MB];
  14. }else {
  15. return [NSString stringWithFormat:@"%.1f GB",((CGFloat)fileSize)/GB];
  16. }
  17. }

10.IP地址

  1. - (NSString *)deviceIPAdress {
  2. NSString *address = @"an error occurred when obtaining ip address";
  3. struct ifaddrs *interfaces = NULL;
  4. struct ifaddrs *temp_addr = NULL;
  5. int success = 0;
  6. success = getifaddrs(&interfaces);
  7. if (success == 0) { // 0 表示获取成功
  8. temp_addr = interfaces;
  9. while (temp_addr != NULL) {
  10. if( temp_addr->ifa_addr->sa_family == AF_INET) {
  11. // Check if interface is en0 which is the wifi connection on the iPhone
  12. if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
  13. // Get NSString from C String
  14. address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
  15. }
  16. }
  17. temp_addr = temp_addr->ifa_next;
  18. }
  19. }
  20. freeifaddrs(interfaces);
  21. return address;
  22. }

11.当前手机连接的WIFI名称(SSID)

  1. - (NSString *)getWifiName
  2. {
  3. NSString *wifiName = nil;
  4. CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
  5. if (!wifiInterfaces) {
  6. return nil;
  7. }
  8. NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;
  9. for (NSString *interfaceName in interfaces) {
  10. CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));
  11. if (dictRef) {
  12. NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;
  13. wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
  14. CFRelease(dictRef);
  15. }
  16. }
  17. CFRelease(wifiInterfaces);
  18. return wifiName;
  19. }

12.设备基本信息

  1. NSLog(@"%@",[[UIDevice currentDevice] name]);//设备名称
  2. NSLog(@"%@",[[UIDevice currentDevice] model]);//设备类型
  3. NSLog(@"%@",[[UIDevice currentDevice] localizedModel]);
  4. NSLog(@"%@",[[UIDevice currentDevice] systemName]);//系统名称
  5. NSLog(@"%@",[[UIDevice currentDevice] systemVersion]);//系统版本


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/736517
推荐阅读
  

闽ICP备14008679号