獲取 iOS 裝置的型別
首先匯入標頭檔案
#include <sys/sysctl.h>
獲取裝置內部型號
+ (NSString*)innerDeviceModleString
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = (char*)malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *innerModle = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
return innerModle;
}
轉換成通用裝置型號
+ (NSString *)currentDeviceModleString {
NSString *deviceModle = [self innerDeviceModleString];
//iPhone
if ([deviceModle isEqualToString:@"iPhone1,1"]) return @"iPhone1";
if ([deviceModle isEqualToString:@"iPhone1,2"]) return @"iPhone3";
if ([deviceModle isEqualToString:@"iPhone2,1"]) return @"iPhone3GS";
if ([deviceModle isEqualToString:@"iPhone3,1"]) return @"iPhone4";
if ([deviceModle isEqualToString:@"iPhone3,2"]) return @"iPhone4";
if ([deviceModle isEqualToString:@"iPhone3,3"]) return @"iPhone4";
if ([deviceModle isEqualToString:@"iPhone4,1"]) return @"iPhone4s";
if ([deviceModle isEqualToString:@"iPhone5,1"]) return @"iPhone5";
if ([deviceModle isEqualToString:@"iPhone5,2"]) return @"iPhone5";
if ([deviceModle isEqualToString:@"iPhone5,3"]) return @"iPhone5C";
if ([deviceModle isEqualToString:@"iPhone5,4"]) return @"iPhone5C";
if ([deviceModle isEqualToString:@"iPhone6,1"]) return @"iPhone5S";
if ([deviceModle isEqualToString:@"iPhone6,2"]) return @"iPhone5S";
if ([deviceModle isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus";
if ([deviceModle isEqualToString:@"iPhone7,2"]) return @"iPhone6";
if ([deviceModle isEqualToString:@"iPhone8,1"]) return @"iPhone6S";
if ([deviceModle isEqualToString:@"iPhone8,2"]) return @"iPhone6SPlus";
//iPot Touch
if ([deviceModle isEqualToString:@"iPod1,1"]) return @"iPodTouch";
if ([deviceModle isEqualToString:@"iPod2,1"]) return @"iPodTouch2";
if ([deviceModle isEqualToString:@"iPod3,1"]) return @"iPodTouch3";
if ([deviceModle isEqualToString:@"iPod4,1"]) return @"iPodTouch4";
if ([deviceModle isEqualToString:@"iPod5,1"]) return @"iPodTouch5";
//iPad
if ([deviceModle isEqualToString:@"iPad1,1"]) return @"iPad";
if ([deviceModle isEqualToString:@"iPad2,1"]) return @"iPad2";
if ([deviceModle isEqualToString:@"iPad2,2"]) return @"iPad2";
if ([deviceModle isEqualToString:@"iPad2,3"]) return @"iPad2";
if ([deviceModle isEqualToString:@"iPad2,4"]) return @"iPad2";
if ([deviceModle isEqualToString:@"iPad2,5"]) return @"iPadMini1";
if ([deviceModle isEqualToString:@"iPad2,6"]) return @"iPadMini1";
if ([deviceModle isEqualToString:@"iPad2,7"]) return @"iPadMini1";
if ([deviceModle isEqualToString:@"iPad3,1"]) return @"iPad3";
if ([deviceModle isEqualToString:@"iPad3,2"]) return @"iPad3";
if ([deviceModle isEqualToString:@"iPad3,3"]) return @"iPad3";
if ([deviceModle isEqualToString:@"iPad3,4"]) return @"iPad4";
if ([deviceModle isEqualToString:@"iPad3,5"]) return @"iPad4";
if ([deviceModle isEqualToString:@"iPad3,6"]) return @"iPad4";
if ([deviceModle isEqualToString:@"iPad4,1"]) return @"iPadAir";
if ([deviceModle isEqualToString:@"iPad4,2"]) return @"iPadAir";
if ([deviceModle isEqualToString:@"iPad4,3"]) return @"iPadAir";
if ([deviceModle isEqualToString:@"iPad4,4"]) return @"iPadMini2";
if ([deviceModle isEqualToString:@"iPad4,5"]) return @"iPadMini2";
if ([deviceModle isEqualToString:@"iPad4,6"]) return @"iPadMini2";
if ([deviceModle isEqualToString:@"iPad4,7"]) return @"iPadMini3";
if ([deviceModle isEqualToString:@"iPad4,8"]) return @"iPadMini3";
if ([deviceModle isEqualToString:@"iPad4,9"]) return @"iPadMini3";
if ([deviceModle isEqualToString:@"iPad5,3"]) return @"iPadAir2";
if ([deviceModle isEqualToString:@"iPad5,4"]) return @"iPadAir2";
// 模擬器
if ([deviceModle isEqualToString:@"i386"]) return @"iPhoneSimulator";
if ([deviceModle isEqualToString:@"x86_64"]) return @"iPhoneSimulator";
if ([deviceModle isEqualToString:@"iPhoneSimulator"]) return @"iPhoneSimulator";
return deviceModle;
}
相關文章
- PHP 獲取裝置型別PHP型別
- iOS裝置具體型號獲取iOS
- 如何獲取iOS裝置的UDIDiOS
- iOS獲取裝置資訊的常用方法iOS
- iOS怎樣獲取裝置唯一識別符號iOS符號
- iPhone X獲取裝置網路型別錯誤分析iPhone型別
- IOS 特定於裝置的開發:獲取額外的裝置資訊iOS
- iOS 獲取本機的裝置資訊UIDeviceiOSUIIDEdev
- iOS獲取當前裝置的資訊-網路相關iOS
- 史上最全的iOS各種裝置資訊獲取總結iOS
- 思路清奇:通過 JavaScript 獲取移動裝置的型號JavaScript
- iphone獲取手機裝置號iPhone
- Flutter 如何獲取裝置的唯一碼Flutter
- js獲取裝置資訊的方法彙總JS
- 獲取redhat linux裸裝置的大小RedhatLinux
- iOS 獲取裝置uuid,公網ip,手機ip等資訊iOSUI
- 關於uni-app獲取裝置IMEI、IMSI、型號、廠商APP
- js判斷裝置型別JS型別
- Android獲取硬體裝置資訊Android
- C#獲取本地串列埠裝置C#串列埠
- modbustcp封裝使用獲取裝置資料示例TCP封裝
- 獲取作業系統型別作業系統型別
- JavaScript獲取物件資料型別JavaScript物件資料型別
- JavaScript如何獲取元素的標籤型別JavaScript型別
- 獲取表的所有列及其型別資訊型別
- 判斷移動裝置型別型別
- android 獲取裝置IP和Mac地址AndroidMac
- iOS 獲取手機型號,XR,XS,MAXiOS
- js獲取事件的型別程式碼例項JS事件型別
- 獲取連線電腦的裝置的所有埠資訊
- Flutter獲取當前網路型別Flutter型別
- .net core 獲取檔案MIME型別型別
- 新版POI如何獲取日期型別的cell的值型別
- C++ 11 新特性之型別推斷與型別獲取C++型別
- javascript獲取移動裝置螢幕尺寸的程式碼JavaScript
- js獲取移動裝置最大化時的尺寸JS
- linux驅動之獲取裝置樹資訊Linux
- 獲取Android裝置唯一標識碼Android