Skip to content

Commit

Permalink
watch devices support
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentneo committed Jan 30, 2023
1 parent 1308486 commit 5a0eadd
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 157 additions & 0 deletions UIDeviceComplete.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
AA1C21AB1F385C2A0095BFBD /* UIDeviceExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1C21A71F385C2A0095BFBD /* UIDeviceExtensionsTests.swift */; };
AAB1EF351F13866F003BBCF2 /* UIDeviceComplete.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAB1EF2B1F13866F003BBCF2 /* UIDeviceComplete.framework */; };
AAB1EF3C1F13866F003BBCF2 /* UIDeviceComplete.h in Headers */ = {isa = PBXBuildFile; fileRef = AAB1EF2E1F13866F003BBCF2 /* UIDeviceComplete.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF72D63129880FAC00B70A2B /* WKDeviceComplete.h in Headers */ = {isa = PBXBuildFile; fileRef = BF72D63029880FAC00B70A2B /* WKDeviceComplete.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF72D63629880FCF00B70A2B /* System.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA1C219A1F385BEC0095BFBD /* System.swift */; };
BF72D638298810D700B70A2B /* DeviceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF72D637298810D700B70A2B /* DeviceModel.swift */; };
BF72D63A2988115000B70A2B /* Identifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF72D6392988115000B70A2B /* Identifier.swift */; };
BF72D63C29881D1A00B70A2B /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF72D63B29881D1A00B70A2B /* Screen.swift */; };
BF72D63E2988206900B70A2B /* WKInterfaceDeviceExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF72D63D2988206900B70A2B /* WKInterfaceDeviceExtensions.swift */; };
BF72D6402988209C00B70A2B /* WKDeviceComplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF72D63F2988209C00B70A2B /* WKDeviceComplete.swift */; };
BFA9121C215B9881000CD8A8 /* DeviceModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFA9121B215B9881000CD8A8 /* DeviceModelTests.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -50,6 +57,13 @@
AAB1EF2F1F13866F003BBCF2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
AAB1EF341F13866F003BBCF2 /* UIDeviceCompleteTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIDeviceCompleteTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
AAB1EF3B1F13866F003BBCF2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BF72D62E29880FAC00B70A2B /* WKDeviceComplete.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WKDeviceComplete.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BF72D63029880FAC00B70A2B /* WKDeviceComplete.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKDeviceComplete.h; sourceTree = "<group>"; };
BF72D637298810D700B70A2B /* DeviceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceModel.swift; sourceTree = "<group>"; };
BF72D6392988115000B70A2B /* Identifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Identifier.swift; sourceTree = "<group>"; };
BF72D63B29881D1A00B70A2B /* Screen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = "<group>"; };
BF72D63D2988206900B70A2B /* WKInterfaceDeviceExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKInterfaceDeviceExtensions.swift; sourceTree = "<group>"; };
BF72D63F2988209C00B70A2B /* WKDeviceComplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKDeviceComplete.swift; sourceTree = "<group>"; };
BFA9121B215B9881000CD8A8 /* DeviceModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeviceModelTests.swift; path = Tests/DeviceModelTests.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand All @@ -69,6 +83,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
BF72D62B29880FAC00B70A2B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand All @@ -77,6 +98,7 @@
children = (
AAB1EF2D1F13866F003BBCF2 /* UIDeviceComplete */,
AAB1EF381F13866F003BBCF2 /* UIDeviceCompleteTests */,
BF72D62F29880FAC00B70A2B /* WKDeviceComplete */,
AAB1EF2C1F13866F003BBCF2 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -86,6 +108,7 @@
children = (
AAB1EF2B1F13866F003BBCF2 /* UIDeviceComplete.framework */,
AAB1EF341F13866F003BBCF2 /* UIDeviceCompleteTests.xctest */,
BF72D62E29880FAC00B70A2B /* WKDeviceComplete.framework */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -127,6 +150,19 @@
name = Sources;
sourceTree = "<group>";
};
BF72D62F29880FAC00B70A2B /* WKDeviceComplete */ = {
isa = PBXGroup;
children = (
BF72D63029880FAC00B70A2B /* WKDeviceComplete.h */,
BF72D637298810D700B70A2B /* DeviceModel.swift */,
BF72D6392988115000B70A2B /* Identifier.swift */,
BF72D63B29881D1A00B70A2B /* Screen.swift */,
BF72D63F2988209C00B70A2B /* WKDeviceComplete.swift */,
BF72D63D2988206900B70A2B /* WKInterfaceDeviceExtensions.swift */,
);
path = WKDeviceComplete;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand All @@ -138,6 +174,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
BF72D62929880FAC00B70A2B /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BF72D63129880FAC00B70A2B /* WKDeviceComplete.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -177,6 +221,24 @@
productReference = AAB1EF341F13866F003BBCF2 /* UIDeviceCompleteTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
BF72D62D29880FAC00B70A2B /* WKDeviceComplete */ = {
isa = PBXNativeTarget;
buildConfigurationList = BF72D63429880FAC00B70A2B /* Build configuration list for PBXNativeTarget "WKDeviceComplete" */;
buildPhases = (
BF72D62929880FAC00B70A2B /* Headers */,
BF72D62A29880FAC00B70A2B /* Sources */,
BF72D62B29880FAC00B70A2B /* Frameworks */,
BF72D62C29880FAC00B70A2B /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = WKDeviceComplete;
productName = WKDeviceComplete;
productReference = BF72D62E29880FAC00B70A2B /* WKDeviceComplete.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -197,6 +259,10 @@
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
BF72D62D29880FAC00B70A2B = {
CreatedOnToolsVersion = 14.2;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = AAB1EF251F13866F003BBCF2 /* Build configuration list for PBXProject "UIDeviceComplete" */;
Expand All @@ -214,6 +280,7 @@
targets = (
AAB1EF2A1F13866F003BBCF2 /* UIDeviceComplete */,
AAB1EF331F13866F003BBCF2 /* UIDeviceCompleteTests */,
BF72D62D29880FAC00B70A2B /* WKDeviceComplete */,
);
};
/* End PBXProject section */
Expand All @@ -233,6 +300,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
BF72D62C29880FAC00B70A2B /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -262,6 +336,19 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
BF72D62A29880FAC00B70A2B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BF72D63E2988206900B70A2B /* WKInterfaceDeviceExtensions.swift in Sources */,
BF72D63629880FCF00B70A2B /* System.swift in Sources */,
BF72D63A2988115000B70A2B /* Identifier.swift in Sources */,
BF72D638298810D700B70A2B /* DeviceModel.swift in Sources */,
BF72D6402988209C00B70A2B /* WKDeviceComplete.swift in Sources */,
BF72D63C29881D1A00B70A2B /* Screen.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
Expand Down Expand Up @@ -475,6 +562,67 @@
};
name = Release;
};
BF72D63229880FAC00B70A2B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nicholas Maccharoli. All rights reserved.";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.vincent-neo.WKDeviceComplete";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Debug;
};
BF72D63329880FAC00B70A2B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 Nicholas Maccharoli. All rights reserved.";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.vincent-neo.WKDeviceComplete";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 4.0;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand Down Expand Up @@ -505,6 +653,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
BF72D63429880FAC00B70A2B /* Build configuration list for PBXNativeTarget "WKDeviceComplete" */ = {
isa = XCConfigurationList;
buildConfigurations = (
BF72D63229880FAC00B70A2B /* Debug */,
BF72D63329880FAC00B70A2B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = AAB1EF221F13866F003BBCF2 /* Project object */;
Expand Down
73 changes: 73 additions & 0 deletions WKDeviceComplete/DeviceModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// DeviceModel.swift
//
// Copyright (c) 2017-2023 Nicholas Maccharoli
// Copyright (c) 2023 Vincent Neo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

public enum DeviceModel: CaseIterable {
case firstGen
case series1
case series2
case series3
case series4
case series5
case se
case series6
case series7
case series8
case se2
case ultra

case unknown
}

// MARK: - init

extension DeviceModel {
init(identifier: Identifier) {
self = DeviceModel.detectWatchModel(with: identifier)
}
}

extension DeviceModel {
fileprivate static func detectWatchModel(with identifier: Identifier) -> DeviceModel {
guard let major = identifier.version.major,
let minor = identifier.version.minor
else { return .unknown }

switch (major, minor) {
case (1, _): return .firstGen
case (2, 3), (2, 4): return .series2
case (2, 6), (2, 7): return .series1
case (3, _): return .series3
case (4, _): return .series4
case (5, 1), (5, 2), (5, 3), (5, 4): return .series5
case (5, 9), (5, 10), (5, 11), (5, 12): return .se
case (6, 1), (6, 2), (6, 3), (6, 4): return .series6
case (6, 6), (6, 7), (6, 8), (6, 9): return .series7
case (6, 10), (6, 11), (6, 12), (6, 13): return .se2
case (6, 14), (6, 15), (6, 16), (6, 17): return .series8
case (6, 18): return .ultra

default: return .unknown
}
}
}
Loading

0 comments on commit 5a0eadd

Please sign in to comment.