IOS 獲取最新裝置型號方法

2021-09-06 18:47:38 字數 4745 閱讀 7170

1.ios 獲取最新裝置型號方法

列表最新對照表:

方法:#import "sys/utsname.h」

struct utsname systeminfo;  

uname(&systeminfo);

nsstring *devicestring = [nsstring stringwithcstring:systeminfo.machine encoding:nsutf8stringencoding];

這樣得到的   devicestring  是iphone5,2 的裝置號,根據對照表可以獲取到當前手機型號。

完整函式:

1

struct

utsname systeminfo;

2 uname(&systeminfo);

3 nsstring *devicestring =[nsstring stringwithcstring:systeminfo.machine encoding:nsutf8stringencoding];

45 nsarray *modelarray =@[ 67

@"i386

", @"

x86_64

", 89

@"iphone1,1

",

10@"

iphone1,2

",

11@"

iphone2,1

",

12@"

iphone3,1

",

13@"

iphone3,2

",

14@"

iphone3,3

",

15@"

iphone4,1

",

16@"

iphone5,1

",

17@"

iphone5,2

",

18@"

iphone5,3

",

19@"

iphone5,4

",

20@"

iphone6,1

",

21@"

iphone6,2

",

2223

@"ipod1,1

",

24@"

ipod2,1

",

25@"

ipod3,1

",

26@"

ipod4,1

",

27@"

ipod5,1

",

2829

@"ipad1,1

",

30@"

ipad2,1

",

31@"

ipad2,2

",

32@"

ipad2,3

",

33@"

ipad2,4

",

34@"

ipad3,1

",

35@"

ipad3,2

",

36@"

ipad3,3

",

37@"

ipad3,4

",

38@"

ipad3,5

",

39@"

ipad3,6

",

4041

@"ipad2,5

",

42@"

ipad2,6

",

43@"

ipad2,7

",

44];

45 nsarray *modelnamearray =@[

4647

@"iphone simulator

", @"

iphone simulator

",

4849

@"iphone 2g

",

50@"

iphone 3g

",

51@"

iphone 3gs

",

52@"

iphone 4(gsm)

",

53@"

iphone 4(gsm rev a)

",

54@"

iphone 4(cdma)

",

55@"

iphone 4s

",

56@"

iphone 5(gsm)

",

57@"

iphone 5(gsm+cdma)

",

58@"

iphone 5c(gsm)

",

59@"

iphone 5c(global)

",

60@"

iphone 5s(gsm)

",

61@"

iphone 5s(global)

",

6263

@"ipod touch 1g

",

64@"

ipod touch 2g

",

65@"

ipod touch 3g

",

66@"

ipod touch 4g

",

67@"

ipod touch 5g

",

6869

@"ipad

",

70@"

ipad 2(wifi)

",

71@"

ipad 2(gsm)

",

72@"

ipad 2(cdma)

",

73@"

ipad 2(wifi + new chip)

",

74@"

ipad 3(wifi)

",

75@"

ipad 3(gsm+cdma)

",

76@"

ipad 3(gsm)

",

77@"

ipad 4(wifi)

",

78@"

ipad 4(gsm)

",

79@"

ipad 4(gsm+cdma)

",

8081

@"ipad mini (wifi)

",

82@"

ipad mini (gsm)

",

83@"

ipad mini (gsm+cdma)"84

];

85 nsinteger modelindex = - 1

; 86 nsstring *modelnamestring =nil;

87 modelindex =[modelarray indexofobject:devicestring];

88if (modelindex >= 0 && modelindex <[modelnamearray count])

9192

93 nslog(@"

----裝置型別---%@

",modelnamestring);

注:struct utsname systeminfo; 這是linux系統放硬體版本的資訊的地方。

附錄:

1

//2 nslog(@"

name: %@

", [[uidevice currentdevice] name]);

3 nslog(@"

systemname: %@

", [[uidevice currentdevice] systemname]);

4 nslog(@"

systemversion: %@

", [[uidevice currentdevice] systemversion]);

5 nslog(@"

model: %@

", [[uidevice currentdevice] model]);

6 nslog(@"

localizedmodel: %@

", [[uidevice currentdevice] localizedmodel]); 78

910 nsdictionary *infodictionary =[[nsbundle mainbundle] infodictionary];

1112

cfshow((__bridge cftyperef)(infodictionary));

1314

//cfbundledisplayname

"];

16//

cfbundleshortversionstring

"];

18//

cfbundleversion」];

----------備註記錄之用

iOS 獲取最新裝置型號方法

1.ios 獲取最新裝置型號方法 列表最新對照表 方法 import sys utsname.h struct utsname systeminfo uname systeminfo nsstring devicestring nsstring stringwithcstring systeminf...

獲取iOS裝置型號的方法總結

三種常用的辦法獲取ios裝置的型號 1.uidevice currentdevice model 推薦 2.uname struct utsname name 使用此函式需要 include 3.sysctlbyname const char name,void oldp,size t oldlen...

獲取iOS裝置型號的方法總結

三種常用的辦法獲取ios裝置的型號 1.uidevice currentdevice model 推薦 2.uname struct utsname name 使用此函式需要 include 3.sysctlbyname const char name,void oldp,size t oldlen...