Skip to content

Commit fe41d18

Browse files
Fix building for visionOS. (#390)
* Fix compile errors on visionOS. # Conflicts: # Source/Device.generated.swift # Source/Device.swift.gyb * Remove references to xrOS that are no longer applicable. * Add TODO comments in code about visionOS proper implementation. * Update changelog. --------- Co-authored-by: Chris Vasselli <[email protected]>
1 parent 6c01329 commit fe41d18

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ pod 'DeviceKit', '~> 5.2'
1111
### Bugfixes
1212

1313
- Fix building SwiftUI previews on macOS properly. ([#389](https://github.com/devicekit/DeviceKit/pull/389))
14+
- Fix building for visionOS. ([#390](https://github.com/devicekit/DeviceKit/pull/390))
1415

1516
### Contributors
1617

1718
Thanks to all the contributers of this release!
1819
- [honghaoz](https://github.com/honghaoz)
20+
- [chrisvasselli](https://github.com/chrisvasselli)
1921

2022
## Version 5.2.1
2123

DeviceKit.xcodeproj/project.pbxproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,12 @@
391391
RUN_CLANG_STATIC_ANALYZER = YES;
392392
SDKROOT = iphoneos;
393393
SKIP_INSTALL = YES;
394+
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
395+
SUPPORTS_MACCATALYST = YES;
394396
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
395397
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
396398
SWIFT_VERSION = 5.0;
397-
TARGETED_DEVICE_FAMILY = "1,2,3,4";
399+
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
398400
TVOS_DEPLOYMENT_TARGET = 11.0;
399401
VERSIONING_SYSTEM = "apple-generic";
400402
VERSION_INFO_PREFIX = "";
@@ -448,8 +450,10 @@
448450
RUN_CLANG_STATIC_ANALYZER = YES;
449451
SDKROOT = iphoneos;
450452
SKIP_INSTALL = YES;
453+
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
454+
SUPPORTS_MACCATALYST = YES;
451455
SWIFT_VERSION = 5.0;
452-
TARGETED_DEVICE_FAMILY = "1,2,3,4";
456+
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
453457
TVOS_DEPLOYMENT_TARGET = 11.0;
454458
VALIDATE_PRODUCT = YES;
455459
VERSIONING_SYSTEM = "apple-generic";

Source/Device.generated.swift

+24-7
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ public enum Device {
628628
case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS"))
629629
default: return unknown(identifier)
630630
}
631+
#elseif os(visionOS)
632+
// TODO: Replace with proper implementation for visionOS.
633+
return unknown(identifier)
631634
#else
632635
return unknown(identifier)
633636
#endif
@@ -879,7 +882,7 @@ public enum Device {
879882
case .simulator(let model): return model.screenRatio
880883
case .unknown: return (width: -1, height: -1)
881884
}
882-
#elseif os(tvOS)
885+
#elseif os(tvOS) || os(visionOS)
883886
return (width: -1, height: -1)
884887
#else
885888
return (width: -1, height: -1)
@@ -986,16 +989,12 @@ public enum Device {
986989

987990
public var isZoomed: Bool? {
988991
guard isCurrent else { return nil }
989-
#if os(xrOS)
990-
return nil
991-
#else
992992
if Int(UIScreen.main.scale.rounded()) == 3 {
993993
// Plus-sized
994994
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
995995
} else {
996996
return UIScreen.main.nativeScale > UIScreen.main.scale
997997
}
998-
#endif
999998
}
1000999

10011000
/// All Touch ID Capable Devices
@@ -1162,6 +1161,9 @@ public enum Device {
11621161
return allTVs
11631162
#elseif os(watchOS)
11641163
return allWatches
1164+
#elseif os(visionOS)
1165+
// TODO: Replace with proper implementation for visionOS.
1166+
return []
11651167
#else
11661168
return []
11671169
#endif
@@ -1401,6 +1403,9 @@ public enum Device {
14011403
}
14021404
#elseif os(tvOS)
14031405
return nil
1406+
#elseif os(visionOS)
1407+
// TODO: Replace with proper implementation for visionOS.
1408+
return nil
14041409
#else
14051410
return nil
14061411
#endif
@@ -1421,7 +1426,7 @@ public enum Device {
14211426

14221427
/// The brightness level of the screen.
14231428
public var screenBrightness: Int {
1424-
#if os(iOS) && !os(xrOS)
1429+
#if os(iOS)
14251430
return Int(UIScreen.main.brightness * 100)
14261431
#else
14271432
return 100
@@ -1554,6 +1559,9 @@ extension Device: CustomStringConvertible {
15541559
case .simulator(let model): return "Simulator (\(model.description))"
15551560
case .unknown(let identifier): return identifier
15561561
}
1562+
#elseif os(visionOS)
1563+
// TODO: Replace with proper implementation for visionOS.
1564+
return "Apple Vision Pro"
15571565
#else
15581566
switch self {
15591567
case .simulator(let model): return "Simulator (\(model.description))"
@@ -1687,6 +1695,9 @@ extension Device: CustomStringConvertible {
16871695
case .simulator(let model): return "Simulator (\(model.safeDescription))"
16881696
case .unknown(let identifier): return identifier
16891697
}
1698+
#elseif os(visionOS)
1699+
// TODO: Replace with proper implementation for visionOS.
1700+
return "Apple Vision Pro"
16901701
#else
16911702
switch self {
16921703
case .simulator(let model): return "Simulator (\(model.safeDescription))"
@@ -1842,7 +1853,7 @@ extension Device.BatteryState: Comparable {
18421853
}
18431854
#endif
18441855

1845-
#if os(iOS) && !os(xrOS)
1856+
#if os(iOS)
18461857
extension Device {
18471858
// MARK: Orientation
18481859
/**
@@ -2326,6 +2337,9 @@ extension Device {
23262337
case .simulator(let model): return model.cpu
23272338
case .unknown: return .unknown
23282339
}
2340+
#elseif os(visionOS)
2341+
// TODO: Replace with proper implementation for visionOS.
2342+
return .unknown
23292343
#else
23302344
return .unknown
23312345
#endif
@@ -2377,6 +2391,9 @@ extension Device.CPU: CustomStringConvertible {
23772391
case .s9: return "S9"
23782392
case .unknown: return "unknown"
23792393
}
2394+
#elseif os(visionOS)
2395+
// TODO: Replace with proper implementation for visionOS.
2396+
return "unknown"
23802397
#else
23812398
return "unknown"
23822399
#endif

Source/Device.swift.gyb

+24-7
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ public enum Device {
421421
case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS"))
422422
default: return unknown(identifier)
423423
}
424+
#elseif os(visionOS)
425+
// TODO: Replace with proper implementation for visionOS.
426+
return unknown(identifier)
424427
#else
425428
return unknown(identifier)
426429
#endif
@@ -482,7 +485,7 @@ public enum Device {
482485
case .simulator(let model): return model.screenRatio
483486
case .unknown: return (width: -1, height: -1)
484487
}
485-
#elseif os(tvOS)
488+
#elseif os(tvOS) || os(visionOS)
486489
return (width: -1, height: -1)
487490
#else
488491
return (width: -1, height: -1)
@@ -589,16 +592,12 @@ public enum Device {
589592

590593
public var isZoomed: Bool? {
591594
guard isCurrent else { return nil }
592-
#if os(xrOS)
593-
return nil
594-
#else
595595
if Int(UIScreen.main.scale.rounded()) == 3 {
596596
// Plus-sized
597597
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
598598
} else {
599599
return UIScreen.main.nativeScale > UIScreen.main.scale
600600
}
601-
#endif
602601
}
603602

604603
/// All Touch ID Capable Devices
@@ -765,6 +764,9 @@ public enum Device {
765764
return allTVs
766765
#elseif os(watchOS)
767766
return allWatches
767+
#elseif os(visionOS)
768+
// TODO: Replace with proper implementation for visionOS.
769+
return []
768770
#else
769771
return []
770772
#endif
@@ -909,6 +911,9 @@ public enum Device {
909911
}
910912
#elseif os(tvOS)
911913
return nil
914+
#elseif os(visionOS)
915+
// TODO: Replace with proper implementation for visionOS.
916+
return nil
912917
#else
913918
return nil
914919
#endif
@@ -929,7 +934,7 @@ public enum Device {
929934

930935
/// The brightness level of the screen.
931936
public var screenBrightness: Int {
932-
#if os(iOS) && !os(xrOS)
937+
#if os(iOS)
933938
return Int(UIScreen.main.brightness * 100)
934939
#else
935940
return 100
@@ -966,6 +971,9 @@ extension Device: CustomStringConvertible {
966971
case .simulator(let model): return "Simulator (\(model.description))"
967972
case .unknown(let identifier): return identifier
968973
}
974+
#elseif os(visionOS)
975+
// TODO: Replace with proper implementation for visionOS.
976+
return "Apple Vision Pro"
969977
#else
970978
switch self {
971979
case .simulator(let model): return "Simulator (\(model.description))"
@@ -1003,6 +1011,9 @@ extension Device: CustomStringConvertible {
10031011
case .simulator(let model): return "Simulator (\(model.safeDescription))"
10041012
case .unknown(let identifier): return identifier
10051013
}
1014+
#elseif os(visionOS)
1015+
// TODO: Replace with proper implementation for visionOS.
1016+
return "Apple Vision Pro"
10061017
#else
10071018
switch self {
10081019
case .simulator(let model): return "Simulator (\(model.safeDescription))"
@@ -1158,7 +1169,7 @@ extension Device.BatteryState: Comparable {
11581169
}
11591170
#endif
11601171

1161-
#if os(iOS) && !os(xrOS)
1172+
#if os(iOS)
11621173
extension Device {
11631174
// MARK: Orientation
11641175
/**
@@ -1496,6 +1507,9 @@ extension Device {
14961507
case .simulator(let model): return model.cpu
14971508
case .unknown: return .unknown
14981509
}
1510+
#elseif os(visionOS)
1511+
// TODO: Replace with proper implementation for visionOS.
1512+
return .unknown
14991513
#else
15001514
return .unknown
15011515
#endif
@@ -1520,6 +1534,9 @@ extension Device.CPU: CustomStringConvertible {
15201534
% end
15211535
case .unknown: return "unknown"
15221536
}
1537+
#elseif os(visionOS)
1538+
// TODO: Replace with proper implementation for visionOS.
1539+
return "unknown"
15231540
#else
15241541
return "unknown"
15251542
#endif

0 commit comments

Comments
 (0)