デバイスのスクリーンサイズで、うまくいかないのであれば、
(出力サイズが変動するのであれば)
デバイス固有名 というのが存在するので、
それで判別した方がいいかもしれません。
以下サンプルです。
swift
1 struct GetDeviceCode {
2 static func DeviceStr ( ) - > String {
3 var size : Int = 0
4 sysctlbyname ( "hw.machine" , nil , & size , nil , 0 )
5 var machine = [ CChar ] ( repeating : 0 , count : Int ( size ) )
6 sysctlbyname ( "hw.machine" , & machine , & size , nil , 0 )
7 let code : String = String ( cString : machine )
8
9 print ( code )
10
11 switch code {
12 case "i386" , "x86_64" :
13 return "Simulator"
14 case "iPod1,1" , "iPod2,1" , "iPod3,1" , "iPod4,1" , "iPod5,1" , "iPod7,1" :
15 return "iPod Touch"
16 case "iPhone3,3" :
17 return "iPhone 4"
18 case "iPhone4,1" :
19 return "iPhone 4S"
20 case "iPhone5,1" , "iPhone5,2" :
21 return "iPhone 5"
22 case "iPhone5,3" , "iPhone5,4" :
23 return "iPhone 5c"
24 case "iPhone6,1" , "iPhone6,2" :
25 return "iPhone 5s"
26 case "iPhone7,1" :
27 return "iPhone 6 Plus"
28 case "iPhone7,2" :
29 return "iPhone 6"
30 case "iPhone8,1" :
31 return "iPhone 6S"
32 case "iPhone8,2" :
33 return "iPhone 6S Plus"
34 case "iPhone8,4" :
35 return "iPhone SE"
36 case "iPhone9,1" , "iPhone9,3" :
37 return "iPhone 7"
38 case "iPhone9,2" , "iPhone9,4" :
39 return "iPhone 7 Plus"
40 case "iPhone10,1" , "iPhone10,4" :
41 return "iPhone 8"
42 case "iPhone10,2" , "iPhone10,5" :
43 return "iPhone 8 Plus"
44 case "iPhone10,3" , "iPhone10,6" :
45 return "iPhone X"
46 case "iPhone11,8" :
47 return "iPhone XR"
48 case "iPhone11,2" :
49 return "iPhone XS"
50 case "iPhone11,4" :
51 return "iPhone XS Max"
52 case "iPhone11,6" :
53 return "iPhone XS Max"
54 case "iPhone12,1" :
55 return "iPhone 11"
56 case "iPhone12,3" :
57 return "iPhone 11 Pro"
58
59 default :
60 return code . contains ( "iPad" ) ? "iPad" : "none info"
61 }
62 }
63 }
ここに、iPhone12系はありませんが、
まず、実機にて、どういった文字列が出力されるか確認し、switch
構文のcase
に加えるといいでしょう。