-
Notifications
You must be signed in to change notification settings - Fork 438
/
Device.generated.swift
1545 lines (1428 loc) · 63.9 KB
/
Device.generated.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===----------------------------------------------------------------------===//
//
// This source file is part of the DeviceKit open source project
//
// Copyright © 2014 - 2018 Dennis Weissmann and the DeviceKit project authors
//
// License: https://github.com/dennisweissmann/DeviceKit/blob/master/LICENSE
// Contributors: https://github.com/dennisweissmann/DeviceKit#contributors
//
//===----------------------------------------------------------------------===//
#if os(watchOS)
import WatchKit
#else
import UIKit
#endif
// MARK: Device
/// This enum is a value-type wrapper and extension of
/// [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/).
///
/// Usage:
///
/// let device = Device.current
///
/// print(device) // prints, for example, "iPhone 6 Plus"
///
/// if device == .iPhone6Plus {
/// // Do something
/// } else {
/// // Do something else
/// }
///
/// ...
///
/// if device.batteryState == .full || device.batteryState >= .charging(75) {
/// print("Your battery is happy! 😊")
/// }
///
/// ...
///
/// if device.batteryLevel >= 50 {
/// install_iOS()
/// } else {
/// showError()
/// }
///
public enum Device {
#if os(iOS)
/// Device is an [iPod touch (5th generation)](https://support.apple.com/kb/SP657)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP657/sp657_ipod-touch_size.jpg)
case iPodTouch5
/// Device is an [iPod touch (6th generation)](https://support.apple.com/kb/SP720)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP720/SP720-ipod-touch-specs-color-sg-2015.jpg)
case iPodTouch6
/// Device is an [iPod touch (7th generation)](https://support.apple.com/kb/SP796)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP796/ipod-touch-7th-gen_2x.png)
case iPodTouch7
/// Device is an [iPhone 4](https://support.apple.com/kb/SP587)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP643/sp643_iphone4s_color_black.jpg)
case iPhone4
/// Device is an [iPhone 4s](https://support.apple.com/kb/SP643)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP643/sp643_iphone4s_color_black.jpg)
case iPhone4s
/// Device is an [iPhone 5](https://support.apple.com/kb/SP655)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP655/sp655_iphone5_color.jpg)
case iPhone5
/// Device is an [iPhone 5c](https://support.apple.com/kb/SP684)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP684/SP684-color_yellow.jpg)
case iPhone5c
/// Device is an [iPhone 5s](https://support.apple.com/kb/SP685)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP685/SP685-color_black.jpg)
case iPhone5s
/// Device is an [iPhone 6](https://support.apple.com/kb/SP705)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP705/SP705-iphone_6-mul.png)
case iPhone6
/// Device is an [iPhone 6 Plus](https://support.apple.com/kb/SP706)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP706/SP706-iphone_6_plus-mul.png)
case iPhone6Plus
/// Device is an [iPhone 6s](https://support.apple.com/kb/SP726)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP726/SP726-iphone6s-gray-select-2015.png)
case iPhone6s
/// Device is an [iPhone 6s Plus](https://support.apple.com/kb/SP727)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP727/SP727-iphone6s-plus-gray-select-2015.png)
case iPhone6sPlus
/// Device is an [iPhone 7](https://support.apple.com/kb/SP743)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP743/iphone7-black.png)
case iPhone7
/// Device is an [iPhone 7 Plus](https://support.apple.com/kb/SP744)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP744/iphone7-plus-black.png)
case iPhone7Plus
/// Device is an [iPhone SE](https://support.apple.com/kb/SP738)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP738/SP738.png)
case iPhoneSE
/// Device is an [iPhone 8](https://support.apple.com/kb/SP767)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP767/iphone8.png)
case iPhone8
/// Device is an [iPhone 8 Plus](https://support.apple.com/kb/SP768)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP768/iphone8plus.png)
case iPhone8Plus
/// Device is an [iPhone X](https://support.apple.com/kb/SP770)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP770/iphonex.png)
case iPhoneX
/// Device is an [iPhone Xs](https://support.apple.com/kb/SP779)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP779/SP779-iphone-xs.jpg)
case iPhoneXS
/// Device is an [iPhone Xs Max](https://support.apple.com/kb/SP780)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP780/SP780-iPhone-Xs-Max.jpg)
case iPhoneXSMax
/// Device is an [iPhone Xʀ](https://support.apple.com/kb/SP781)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP781/SP781-iPhone-xr.jpg)
case iPhoneXR
/// Device is an [iPhone 11](https://support.apple.com/kb/SP804)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP804/sp804-iphone11_2x.png)
case iPhone11
/// Device is an [iPhone 11 Pro](https://support.apple.com/kb/SP805)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP805/sp805-iphone11pro_2x.png)
case iPhone11Pro
/// Device is an [iPhone 11 Pro Max](https://support.apple.com/kb/SP806)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP806/sp806-iphone11pro-max_2x.png)
case iPhone11ProMax
/// Device is an [iPad 2](https://support.apple.com/kb/SP622)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP622/SP622_01-ipad2-mul.png)
case iPad2
/// Device is an [iPad (3rd generation)](https://support.apple.com/kb/SP647)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg)
case iPad3
/// Device is an [iPad (4th generation)](https://support.apple.com/kb/SP662)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP662/sp662_ipad-4th-gen_color.jpg)
case iPad4
/// Device is an [iPad Air](https://support.apple.com/kb/SP692)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP692/SP692-specs_color-mul.png)
case iPadAir
/// Device is an [iPad Air 2](https://support.apple.com/kb/SP708)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP708/SP708-space_gray.jpeg)
case iPadAir2
/// Device is an [iPad (5th generation)](https://support.apple.com/kb/SP751)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP751/ipad_5th_generation.png)
case iPad5
/// Device is an [iPad (6th generation)](https://support.apple.com/kb/SP774)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP774/sp774-ipad-6-gen_2x.png)
case iPad6
/// Device is an [iPad Air (3rd generation)](https://support.apple.com/kb/SP787)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP787/ipad-air-2019.jpg)
case iPadAir3
/// Device is an [iPad (7th generation)](https://support.apple.com/kb/SP807)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP807/sp807-ipad-7th-gen_2x.png)
case iPad7
/// Device is an [iPad Mini](https://support.apple.com/kb/SP661)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP661/sp661_ipad_mini_color.jpg)
case iPadMini
/// Device is an [iPad Mini 2](https://support.apple.com/kb/SP693)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP693/SP693-specs_color-mul.png)
case iPadMini2
/// Device is an [iPad Mini 3](https://support.apple.com/kb/SP709)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP709/SP709-space_gray.jpeg)
case iPadMini3
/// Device is an [iPad Mini 4](https://support.apple.com/kb/SP725)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP725/SP725ipad-mini-4.png)
case iPadMini4
/// Device is an [iPad Mini (5th generation)](https://support.apple.com/kb/SP788)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP788/ipad-mini-2019.jpg)
case iPadMini5
/// Device is an [iPad Pro 9.7-inch](https://support.apple.com/kb/SP739)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP739/SP739.png)
case iPadPro9Inch
/// Device is an [iPad Pro 12-inch](https://support.apple.com/kb/SP723)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP723/SP723-iPad_Pro_2x.png)
case iPadPro12Inch
/// Device is an [iPad Pro 12-inch (2nd generation)](https://support.apple.com/kb/SP761)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-12in-hero-201706.png)
case iPadPro12Inch2
/// Device is an [iPad Pro 10.5-inch](https://support.apple.com/kb/SP762)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP761/ipad-pro-10in-hero-201706.png)
case iPadPro10Inch
/// Device is an [iPad Pro 11-inch](https://support.apple.com/kb/SP784)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP784/ipad-pro-11-2018_2x.png)
case iPadPro11Inch
/// Device is an [iPad Pro 12.9-inch (3rd generation)](https://support.apple.com/kb/SP785)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP785/ipad-pro-12-2018_2x.png)
case iPadPro12Inch3
/// Device is a [HomePod](https://support.apple.com/kb/SP773)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP773/homepod_space_gray_large_2x.jpg)
case homePod
#elseif os(tvOS)
/// Device is an [Apple TV HD](https://support.apple.com/kb/SP724) (Previously Apple TV (4th generation))
///
/// ![Image](http://images.apple.com/v/tv/c/images/overview/buy_tv_large_2x.jpg)
case appleTVHD
/// Device is an [Apple TV 4K](https://support.apple.com/kb/SP769)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP769/appletv4k.png)
case appleTV4K
#elseif os(watchOS)
/// Device is an [Apple Watch (1st generation)](https://support.apple.com/kb/SP735)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM784/en_US/apple_watch_sport-240.png)
case appleWatchSeries0_38mm
/// Device is an [Apple Watch (1st generation)](https://support.apple.com/kb/SP735)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM784/en_US/apple_watch_sport-240.png)
case appleWatchSeries0_42mm
/// Device is an [Apple Watch Series 1](https://support.apple.com/kb/SP745)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM848/en_US/applewatch-series2-aluminum-temp-240.png)
case appleWatchSeries1_38mm
/// Device is an [Apple Watch Series 1](https://support.apple.com/kb/SP745)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM848/en_US/applewatch-series2-aluminum-temp-240.png)
case appleWatchSeries1_42mm
/// Device is an [Apple Watch Series 2](https://support.apple.com/kb/SP746)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM852/en_US/applewatch-series2-hermes-240.png)
case appleWatchSeries2_38mm
/// Device is an [Apple Watch Series 2](https://support.apple.com/kb/SP746)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM852/en_US/applewatch-series2-hermes-240.png)
case appleWatchSeries2_42mm
/// Device is an [Apple Watch Series 3](https://support.apple.com/kb/SP766)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM893/en_US/apple-watch-s3-nikeplus-240.png)
case appleWatchSeries3_38mm
/// Device is an [Apple Watch Series 3](https://support.apple.com/kb/SP766)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM893/en_US/apple-watch-s3-nikeplus-240.png)
case appleWatchSeries3_42mm
/// Device is an [Apple Watch Series 4](https://support.apple.com/kb/SP778)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM911/en_US/aw-series4-nike-240.png)
case appleWatchSeries4_40mm
/// Device is an [Apple Watch Series 4](https://support.apple.com/kb/SP778)
///
/// ![Image](https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM911/en_US/aw-series4-nike-240.png)
case appleWatchSeries4_44mm
/// Device is an [Apple Watch Series 5](https://support.apple.com/kb/SP808)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP808/sp808-apple-watch-series-5_2x.png)
case appleWatchSeries5_40mm
/// Device is an [Apple Watch Series 5](https://support.apple.com/kb/SP808)
///
/// ![Image](https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP808/sp808-apple-watch-series-5_2x.png)
case appleWatchSeries5_44mm
#endif
/// Device is [Simulator](https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/Introduction/Introduction.html)
///
/// ![Image](https://developer.apple.com/assets/elements/icons/256x256/xcode-6.png)
indirect case simulator(Device)
/// Device is not yet known (implemented)
/// You can still use this enum as before but the description equals the identifier (you can get multiple identifiers for the same product class
/// (e.g. "iPhone6,1" or "iPhone 6,2" do both mean "iPhone 5s"))
case unknown(String)
/// Returns a `Device` representing the current device this software runs on.
public static var current: Device {
return Device.mapToDevice(identifier: Device.identifier)
}
/// Gets the identifier from the system, such as "iPhone7,1".
public static var identifier: String = {
var systemInfo = utsname()
uname(&systemInfo)
let mirror = Mirror(reflecting: systemInfo.machine)
let identifier = mirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
}()
/// Maps an identifier to a Device. If the identifier can not be mapped to an existing device, `UnknownDevice(identifier)` is returned.
///
/// - parameter identifier: The device identifier, e.g. "iPhone7,1". Can be obtained from `Device.identifier`.
///
/// - returns: An initialized `Device`.
public static func mapToDevice(identifier: String) -> Device { // swiftlint:disable:this cyclomatic_complexity function_body_length
#if os(iOS)
switch identifier {
case "iPod5,1": return iPodTouch5
case "iPod7,1": return iPodTouch6
case "iPod9,1": return iPodTouch7
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return iPhone4
case "iPhone4,1": return iPhone4s
case "iPhone5,1", "iPhone5,2": return iPhone5
case "iPhone5,3", "iPhone5,4": return iPhone5c
case "iPhone6,1", "iPhone6,2": return iPhone5s
case "iPhone7,2": return iPhone6
case "iPhone7,1": return iPhone6Plus
case "iPhone8,1": return iPhone6s
case "iPhone8,2": return iPhone6sPlus
case "iPhone9,1", "iPhone9,3": return iPhone7
case "iPhone9,2", "iPhone9,4": return iPhone7Plus
case "iPhone8,4": return iPhoneSE
case "iPhone10,1", "iPhone10,4": return iPhone8
case "iPhone10,2", "iPhone10,5": return iPhone8Plus
case "iPhone10,3", "iPhone10,6": return iPhoneX
case "iPhone11,2": return iPhoneXS
case "iPhone11,4", "iPhone11,6": return iPhoneXSMax
case "iPhone11,8": return iPhoneXR
case "iPhone12,1": return iPhone11
case "iPhone12,3": return iPhone11Pro
case "iPhone12,5": return iPhone11ProMax
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return iPad2
case "iPad3,1", "iPad3,2", "iPad3,3": return iPad3
case "iPad3,4", "iPad3,5", "iPad3,6": return iPad4
case "iPad4,1", "iPad4,2", "iPad4,3": return iPadAir
case "iPad5,3", "iPad5,4": return iPadAir2
case "iPad6,11", "iPad6,12": return iPad5
case "iPad7,5", "iPad7,6": return iPad6
case "iPad11,3", "iPad11,4": return iPadAir3
case "iPad7,11", "iPad7,12": return iPad7
case "iPad2,5", "iPad2,6", "iPad2,7": return iPadMini
case "iPad4,4", "iPad4,5", "iPad4,6": return iPadMini2
case "iPad4,7", "iPad4,8", "iPad4,9": return iPadMini3
case "iPad5,1", "iPad5,2": return iPadMini4
case "iPad11,1", "iPad11,2": return iPadMini5
case "iPad6,3", "iPad6,4": return iPadPro9Inch
case "iPad6,7", "iPad6,8": return iPadPro12Inch
case "iPad7,1", "iPad7,2": return iPadPro12Inch2
case "iPad7,3", "iPad7,4": return iPadPro10Inch
case "iPad8,1", "iPad8,2", "iPad8,3", "iPad8,4": return iPadPro11Inch
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return iPadPro12Inch3
case "AudioAccessory1,1": return homePod
case "i386", "x86_64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))
default: return unknown(identifier)
}
#elseif os(tvOS)
switch identifier {
case "AppleTV5,3": return appleTVHD
case "AppleTV6,2": return appleTV4K
case "i386", "x86_64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))
default: return unknown(identifier)
}
#elseif os(watchOS)
switch identifier {
case "Watch1,1": return appleWatchSeries0_38mm
case "Watch1,2": return appleWatchSeries0_42mm
case "Watch2,6": return appleWatchSeries1_38mm
case "Watch2,7": return appleWatchSeries1_42mm
case "Watch2,3": return appleWatchSeries2_38mm
case "Watch2,4": return appleWatchSeries2_42mm
case "Watch3,1", "Watch3,3": return appleWatchSeries3_38mm
case "Watch3,2", "Watch3,4": return appleWatchSeries3_42mm
case "Watch4,1", "Watch4,3": return appleWatchSeries4_40mm
case "Watch4,2", "Watch4,4": return appleWatchSeries4_44mm
case "Watch5,1", "Watch5,3": return appleWatchSeries5_40mm
case "Watch5,2", "Watch5,4": return appleWatchSeries5_44mm
case "i386", "x86_64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS"))
default: return unknown(identifier)
}
#endif
}
/// Get the real device from a device.
/// If the device is a an iPhone8Plus simulator this function returns .iPhone8Plus (the real device).
/// If the parameter is a real device, this function returns just that passed parameter.
///
/// - parameter device: A device.
///
/// - returns: the underlying device If the `device` is a `simulator`,
/// otherwise return the `device`.
public static func realDevice(from device: Device) -> Device {
if case let .simulator(model) = device {
return model
}
return device
}
#if os(iOS) || os(watchOS)
/// Returns diagonal screen length in inches
public var diagonal: Double {
#if os(iOS)
switch self {
case .iPodTouch5: return 4
case .iPodTouch6: return 4
case .iPodTouch7: return 4
case .iPhone4: return 3.5
case .iPhone4s: return 3.5
case .iPhone5: return 4
case .iPhone5c: return 4
case .iPhone5s: return 4
case .iPhone6: return 4.7
case .iPhone6Plus: return 5.5
case .iPhone6s: return 4.7
case .iPhone6sPlus: return 5.5
case .iPhone7: return 4.7
case .iPhone7Plus: return 5.5
case .iPhoneSE: return 4
case .iPhone8: return 4.7
case .iPhone8Plus: return 5.5
case .iPhoneX: return 5.8
case .iPhoneXS: return 5.8
case .iPhoneXSMax: return 6.5
case .iPhoneXR: return 6.1
case .iPhone11: return 6.1
case .iPhone11Pro: return 5.8
case .iPhone11ProMax: return 6.5
case .iPad2: return 9.7
case .iPad3: return 9.7
case .iPad4: return 9.7
case .iPadAir: return 9.7
case .iPadAir2: return 9.7
case .iPad5: return 9.7
case .iPad6: return 9.7
case .iPadAir3: return 10.5
case .iPad7: return 10.2
case .iPadMini: return 7.9
case .iPadMini2: return 7.9
case .iPadMini3: return 7.9
case .iPadMini4: return 7.9
case .iPadMini5: return 7.9
case .iPadPro9Inch: return 9.7
case .iPadPro12Inch: return 12.9
case .iPadPro12Inch2: return 12.9
case .iPadPro10Inch: return 10.5
case .iPadPro11Inch: return 11.0
case .iPadPro12Inch3: return 12.9
case .homePod: return -1
case .simulator(let model): return model.diagonal
case .unknown: return -1
}
#elseif os(watchOS)
switch self {
case .appleWatchSeries0_38mm: return 1.5
case .appleWatchSeries0_42mm: return 1.6
case .appleWatchSeries1_38mm: return 1.5
case .appleWatchSeries1_42mm: return 1.6
case .appleWatchSeries2_38mm: return 1.5
case .appleWatchSeries2_42mm: return 1.6
case .appleWatchSeries3_38mm: return 1.5
case .appleWatchSeries3_42mm: return 1.6
case .appleWatchSeries4_40mm: return 1.8
case .appleWatchSeries4_44mm: return 2.0
case .appleWatchSeries5_40mm: return 1.8
case .appleWatchSeries5_44mm: return 2.0
case .simulator(let model): return model.diagonal
case .unknown: return -1
}
#endif
}
#endif
/// Returns screen ratio as a tuple
public var screenRatio: (width: Double, height: Double) {
#if os(iOS)
switch self {
case .iPodTouch5: return (width: 9, height: 16)
case .iPodTouch6: return (width: 9, height: 16)
case .iPodTouch7: return (width: 9, height: 16)
case .iPhone4: return (width: 2, height: 3)
case .iPhone4s: return (width: 2, height: 3)
case .iPhone5: return (width: 9, height: 16)
case .iPhone5c: return (width: 9, height: 16)
case .iPhone5s: return (width: 9, height: 16)
case .iPhone6: return (width: 9, height: 16)
case .iPhone6Plus: return (width: 9, height: 16)
case .iPhone6s: return (width: 9, height: 16)
case .iPhone6sPlus: return (width: 9, height: 16)
case .iPhone7: return (width: 9, height: 16)
case .iPhone7Plus: return (width: 9, height: 16)
case .iPhoneSE: return (width: 9, height: 16)
case .iPhone8: return (width: 9, height: 16)
case .iPhone8Plus: return (width: 9, height: 16)
case .iPhoneX: return (width: 9, height: 19.5)
case .iPhoneXS: return (width: 9, height: 19.5)
case .iPhoneXSMax: return (width: 9, height: 19.5)
case .iPhoneXR: return (width: 9, height: 19.5)
case .iPhone11: return (width: 9, height: 19.5)
case .iPhone11Pro: return (width: 9, height: 19.5)
case .iPhone11ProMax: return (width: 9, height: 19.5)
case .iPad2: return (width: 3, height: 4)
case .iPad3: return (width: 3, height: 4)
case .iPad4: return (width: 3, height: 4)
case .iPadAir: return (width: 3, height: 4)
case .iPadAir2: return (width: 3, height: 4)
case .iPad5: return (width: 3, height: 4)
case .iPad6: return (width: 3, height: 4)
case .iPadAir3: return (width: 3, height: 4)
case .iPad7: return (width: 3, height: 4)
case .iPadMini: return (width: 3, height: 4)
case .iPadMini2: return (width: 3, height: 4)
case .iPadMini3: return (width: 3, height: 4)
case .iPadMini4: return (width: 3, height: 4)
case .iPadMini5: return (width: 3, height: 4)
case .iPadPro9Inch: return (width: 3, height: 4)
case .iPadPro12Inch: return (width: 3, height: 4)
case .iPadPro12Inch2: return (width: 3, height: 4)
case .iPadPro10Inch: return (width: 3, height: 4)
case .iPadPro11Inch: return (width: 139, height: 199)
case .iPadPro12Inch3: return (width: 512, height: 683)
case .homePod: return (width: 4, height: 5)
case .simulator(let model): return model.screenRatio
case .unknown: return (width: -1, height: -1)
}
#elseif os(watchOS)
switch self {
case .appleWatchSeries0_38mm: return (width: 4, height: 5)
case .appleWatchSeries0_42mm: return (width: 4, height: 5)
case .appleWatchSeries1_38mm: return (width: 4, height: 5)
case .appleWatchSeries1_42mm: return (width: 4, height: 5)
case .appleWatchSeries2_38mm: return (width: 4, height: 5)
case .appleWatchSeries2_42mm: return (width: 4, height: 5)
case .appleWatchSeries3_38mm: return (width: 4, height: 5)
case .appleWatchSeries3_42mm: return (width: 4, height: 5)
case .appleWatchSeries4_40mm: return (width: 4, height: 5)
case .appleWatchSeries4_44mm: return (width: 4, height: 5)
case .appleWatchSeries5_40mm: return (width: 4, height: 5)
case .appleWatchSeries5_44mm: return (width: 4, height: 5)
case .simulator(let model): return model.screenRatio
case .unknown: return (width: -1, height: -1)
}
#elseif os(tvOS)
return (width: -1, height: -1)
#endif
}
#if os(iOS)
/// All iPods
public static var allPods: [Device] {
return [.iPodTouch5, .iPodTouch6, .iPodTouch7]
}
/// All iPhones
public static var allPhones: [Device] {
return [.iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
}
/// All iPads
public static var allPads: [Device] {
return [.iPad2, .iPad3, .iPad4, .iPadAir, .iPadAir2, .iPad5, .iPad6, .iPadAir3, .iPad7, .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadMini5, .iPadPro9Inch, .iPadPro12Inch, .iPadPro12Inch2, .iPadPro10Inch, .iPadPro11Inch, .iPadPro12Inch3]
}
/// All X-Series Devices
@available(*, deprecated, renamed: "allDevicesWithSensorHousing")
public static var allXSeriesDevices: [Device] {
return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
}
/// All Plus and Max-Sized Devices
public static var allPlusSizedDevices: [Device] {
return [.iPhone6Plus, .iPhone6sPlus, .iPhone7Plus, .iPhone8Plus, .iPhoneXSMax, .iPhone11ProMax]
}
/// All Pro Devices
public static var allProDevices: [Device] {
return [.iPhone11Pro, .iPhone11ProMax, .iPadPro9Inch, .iPadPro12Inch, .iPadPro12Inch2, .iPadPro10Inch, .iPadPro11Inch, .iPadPro12Inch3]
}
/// All mini Devices
public static var allMiniDevices: [Device] {
return [.iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadMini5]
}
/// All simulator iPods
public static var allSimulatorPods: [Device] {
return allPods.map(Device.simulator)
}
/// All simulator iPhones
public static var allSimulatorPhones: [Device] {
return allPhones.map(Device.simulator)
}
/// All simulator iPads
public static var allSimulatorPads: [Device] {
return allPads.map(Device.simulator)
}
/// All simulator iPad mini
public static var allSimulatorMiniDevices: [Device] {
return allMiniDevices.map(Device.simulator)
}
/// All simulator X series Devices
@available(*, deprecated, renamed: "allSimulatorDevicesWithSensorHousing")
public static var allSimulatorXSeriesDevices: [Device] {
return allDevicesWithSensorHousing.map(Device.simulator)
}
/// All simulator Plus and Max-Sized Devices
public static var allSimulatorPlusSizedDevices: [Device] {
return allPlusSizedDevices.map(Device.simulator)
}
/// All simulator Pro Devices
public static var allSimulatorProDevices: [Device] {
return allProDevices.map(Device.simulator)
}
/// Returns whether the device is an iPod (real or simulator)
public var isPod: Bool {
return isOneOf(Device.allPods) || isOneOf(Device.allSimulatorPods)
}
/// Returns whether the device is an iPhone (real or simulator)
public var isPhone: Bool {
return (isOneOf(Device.allPhones)
|| isOneOf(Device.allSimulatorPhones)
|| (UIDevice.current.userInterfaceIdiom == .phone && isCurrent)) && !isPod
}
/// Returns whether the device is an iPad (real or simulator)
public var isPad: Bool {
return isOneOf(Device.allPads)
|| isOneOf(Device.allSimulatorPads)
|| (UIDevice.current.userInterfaceIdiom == .pad && isCurrent)
}
/// Returns whether the device is any of the simulator
/// Useful when there is a need to check and skip running a portion of code (location request or others)
public var isSimulator: Bool {
return isOneOf(Device.allSimulators)
}
/// If this device is a simulator return the underlying device,
/// otherwise return `self`.
public var realDevice: Device {
return Device.realDevice(from: self)
}
public var isZoomed: Bool? {
guard isCurrent else { return nil }
if Int(UIScreen.main.scale.rounded()) == 3 {
// Plus-sized
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
} else {
return UIScreen.main.nativeScale > UIScreen.main.scale
}
}
/// All Touch ID Capable Devices
public static var allTouchIDCapableDevices: [Device] {
return [.iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPadAir2, .iPad5, .iPad6, .iPadAir3, .iPad7, .iPadMini3, .iPadMini4, .iPadMini5, .iPadPro9Inch, .iPadPro12Inch, .iPadPro12Inch2, .iPadPro10Inch]
}
/// All Face ID Capable Devices
public static var allFaceIDCapableDevices: [Device] {
return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax, .iPadPro11Inch, .iPadPro12Inch3]
}
/// All Devices with Touch ID or Face ID
public static var allBiometricAuthenticationCapableDevices: [Device] {
return [.iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax, .iPadAir2, .iPad5, .iPad6, .iPadAir3, .iPad7, .iPadMini3, .iPadMini4, .iPadMini5, .iPadPro9Inch, .iPadPro12Inch, .iPadPro12Inch2, .iPadPro10Inch, .iPadPro11Inch, .iPadPro12Inch3]
}
/// Returns whether or not the device has Touch ID
public var isTouchIDCapable: Bool {
return isOneOf(Device.allTouchIDCapableDevices) || isOneOf(Device.allTouchIDCapableDevices.map(Device.simulator))
}
/// Returns whether or not the device has Face ID
public var isFaceIDCapable: Bool {
return isOneOf(Device.allFaceIDCapableDevices) || isOneOf(Device.allFaceIDCapableDevices.map(Device.simulator))
}
/// Returns whether or not the device has any biometric sensor (i.e. Touch ID or Face ID)
public var hasBiometricSensor: Bool {
return isTouchIDCapable || isFaceIDCapable
}
/// All devices that feature a sensor housing in the screen
public static var allDevicesWithSensorHousing: [Device] {
return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
}
/// All simulator devices that feature a sensor housing in the screen
public static var allSimulatorDevicesWithSensorHousing: [Device] {
return allDevicesWithSensorHousing.map(Device.simulator)
}
/// Returns whether or not the device has a sensor housing
public var hasSensorHousing: Bool {
return isOneOf(Device.allDevicesWithSensorHousing) || isOneOf(Device.allDevicesWithSensorHousing.map(Device.simulator))
}
/// All devices that feature a screen with rounded corners.
public static var allDevicesWithRoundedDisplayCorners: [Device] {
return [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax, .iPadPro11Inch, .iPadPro12Inch3]
}
/// Returns whether or not the device has a screen with rounded corners.
public var hasRoundedDisplayCorners: Bool {
return isOneOf(Device.allDevicesWithRoundedDisplayCorners) || isOneOf(Device.allDevicesWithRoundedDisplayCorners.map(Device.simulator))
}
/// All devices that have 3D Touch support.
public static var allDevicesWith3dTouchSupport: [Device] {
return [.iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax]
}
/// Returns whether or not the device has 3D Touch support.
public var has3dTouchSupport: Bool {
return isOneOf(Device.allDevicesWith3dTouchSupport) || isOneOf(Device.allDevicesWith3dTouchSupport.map(Device.simulator))
}
/// All devices that support wireless charging.
public static var allDevicesWithWirelessChargingSupport: [Device] {
return [.iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax]
}
/// Returns whether or not the device supports wireless charging
public var supportsWirelessCharging: Bool {
return isOneOf(Device.allDevicesWithWirelessChargingSupport) || isOneOf(Device.allDevicesWithWirelessChargingSupport.map(Device.simulator))
}
#elseif os(tvOS)
/// All TVs
public static var allTVs: [Device] {
return [.appleTVHD, .appleTV4K]
}
/// All simulator TVs
public static var allSimulatorTVs: [Device] {
return allTVs.map(Device.simulator)
}
#elseif os(watchOS)
/// All Watches
public static var allWatches: [Device] {
return [.appleWatchSeries0_38mm, .appleWatchSeries0_42mm, .appleWatchSeries1_38mm, .appleWatchSeries1_42mm, .appleWatchSeries2_38mm, .appleWatchSeries2_42mm, .appleWatchSeries3_38mm, .appleWatchSeries3_42mm, .appleWatchSeries4_40mm, .appleWatchSeries4_44mm, .appleWatchSeries5_40mm, .appleWatchSeries5_44mm]
}
/// All simulator Watches
public static var allSimulatorWatches: [Device] {
return allWatches.map(Device.simulator)
}
/// All watches that have Force Touch support.
public static var allWatchesWithForceTouchSupport: [Device] {
return [.appleWatchSeries0_38mm, .appleWatchSeries0_42mm, .appleWatchSeries1_38mm, .appleWatchSeries1_42mm, .appleWatchSeries2_38mm, .appleWatchSeries2_42mm, .appleWatchSeries3_38mm, .appleWatchSeries3_42mm, .appleWatchSeries4_40mm, .appleWatchSeries4_44mm, .appleWatchSeries5_40mm, .appleWatchSeries5_44mm]
}
/// Returns whether or not the device has Force Touch support.
public var hasForceTouchSupport: Bool {
return isOneOf(Device.allWatchesWithForceTouchSupport) || isOneOf(Device.allWatchesWithForceTouchSupport.map(Device.simulator))
}
#endif
/// All real devices (i.e. all devices except for all simulators)
public static var allRealDevices: [Device] {
#if os(iOS)
return allPods + allPhones + allPads
#elseif os(tvOS)
return allTVs
#elseif os(watchOS)
return allWatches
#endif
}
/// All simulators
public static var allSimulators: [Device] {
return allRealDevices.map(Device.simulator)
}
/**
This method saves you in many cases from the need of updating your code with every new device.
Most uses for an enum like this are the following:
```
switch Device.current {
case .iPodTouch5, .iPodTouch6: callMethodOnIPods()
case .iPhone4, iPhone4s, .iPhone5, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX: callMethodOnIPhones()
case .iPad2, .iPad3, .iPad4, .iPadAir, .iPadAir2, .iPadMini, .iPadMini2, .iPadMini3, .iPadMini4, .iPadPro: callMethodOnIPads()
default: break
}
```
This code can now be replaced with
```
let device = Device.current
if device.isOneOf(Device.allPods) {
callMethodOnIPods()
} else if device.isOneOf(Device.allPhones) {
callMethodOnIPhones()
} else if device.isOneOf(Device.allPads) {
callMethodOnIPads()
}
```
- parameter devices: An array of devices.
- returns: Returns whether the current device is one of the passed in ones.
*/
public func isOneOf(_ devices: [Device]) -> Bool {
return devices.contains(self)
}
// MARK: Current Device
/// Whether or not the current device is the current device.
private var isCurrent: Bool {
return self == Device.current
}
/// The name identifying the device (e.g. "Dennis' iPhone").
public var name: String? {
guard isCurrent else { return nil }
#if os(watchOS)
return WKInterfaceDevice.current().name
#else
return UIDevice.current.name
#endif
}
/// The name of the operating system running on the device represented by the receiver (e.g. "iOS" or "tvOS").
public var systemName: String? {
guard isCurrent else { return nil }
#if os(watchOS)
return WKInterfaceDevice.current().systemName
#else
return UIDevice.current.systemName
#endif
}
/// The current version of the operating system (e.g. 8.4 or 9.2).
public var systemVersion: String? {
guard isCurrent else { return nil }
#if os(watchOS)
return WKInterfaceDevice.current().systemVersion
#else
return UIDevice.current.systemVersion
#endif
}
/// The model of the device (e.g. "iPhone" or "iPod Touch").
public var model: String? {
guard isCurrent else { return nil }
#if os(watchOS)
return WKInterfaceDevice.current().model
#else
return UIDevice.current.model
#endif
}
/// The model of the device as a localized string.
public var localizedModel: String? {
guard isCurrent else { return nil }
#if os(watchOS)
return WKInterfaceDevice.current().localizedModel
#else
return UIDevice.current.localizedModel
#endif
}
/// PPI (Pixels per Inch) on the current device's screen (if applicable). When the device is not applicable this property returns nil.
public var ppi: Int? {
#if os(iOS)
switch self {
case .iPodTouch5: return 326
case .iPodTouch6: return 326
case .iPodTouch7: return 326
case .iPhone4: return 326
case .iPhone4s: return 326
case .iPhone5: return 326
case .iPhone5c: return 326
case .iPhone5s: return 326
case .iPhone6: return 326
case .iPhone6Plus: return 401
case .iPhone6s: return 326
case .iPhone6sPlus: return 401
case .iPhone7: return 326
case .iPhone7Plus: return 401
case .iPhoneSE: return 326
case .iPhone8: return 326
case .iPhone8Plus: return 401
case .iPhoneX: return 458
case .iPhoneXS: return 458
case .iPhoneXSMax: return 458
case .iPhoneXR: return 326
case .iPhone11: return 326
case .iPhone11Pro: return 458
case .iPhone11ProMax: return 458
case .iPad2: return 132
case .iPad3: return 264
case .iPad4: return 264
case .iPadAir: return 264
case .iPadAir2: return 264
case .iPad5: return 264
case .iPad6: return 264
case .iPadAir3: return 264
case .iPad7: return 264
case .iPadMini: return 163
case .iPadMini2: return 326
case .iPadMini3: return 326
case .iPadMini4: return 326
case .iPadMini5: return 326
case .iPadPro9Inch: return 264
case .iPadPro12Inch: return 264
case .iPadPro12Inch2: return 264
case .iPadPro10Inch: return 264
case .iPadPro11Inch: return 264
case .iPadPro12Inch3: return 264
case .homePod: return -1
case .simulator(let model): return model.ppi
case .unknown: return nil
}
#elseif os(watchOS)
switch self {
case .appleWatchSeries0_38mm: return 290
case .appleWatchSeries0_42mm: return 303
case .appleWatchSeries1_38mm: return 290
case .appleWatchSeries1_42mm: return 303
case .appleWatchSeries2_38mm: return 290
case .appleWatchSeries2_42mm: return 303
case .appleWatchSeries3_38mm: return 290
case .appleWatchSeries3_42mm: return 303
case .appleWatchSeries4_40mm: return 326
case .appleWatchSeries4_44mm: return 326
case .appleWatchSeries5_40mm: return 326
case .appleWatchSeries5_44mm: return 326
case .simulator(let model): return model.ppi
case .unknown: return nil
}
#elseif os(tvOS)
return nil
#endif
}
/// True when a Guided Access session is currently active; otherwise, false.
public var isGuidedAccessSessionActive: Bool {
#if os(iOS)
#if swift(>=4.2)
return UIAccessibility.isGuidedAccessEnabled
#else
return UIAccessibilityIsGuidedAccessEnabled()
#endif
#else
return false
#endif
}
/// The brightness level of the screen.
public var screenBrightness: Int {
#if os(iOS)
return Int(UIScreen.main.brightness * 100)
#else
return 100
#endif
}
}
// MARK: CustomStringConvertible
extension Device: CustomStringConvertible {
/// A textual representation of the device.
public var description: String {
#if os(iOS)
switch self {
case .iPodTouch5: return "iPod touch (5th generation)"
case .iPodTouch6: return "iPod touch (6th generation)"
case .iPodTouch7: return "iPod touch (7th generation)"
case .iPhone4: return "iPhone 4"
case .iPhone4s: return "iPhone 4s"
case .iPhone5: return "iPhone 5"