diff --git a/Package.swift b/Package.swift index 8ea98c7f..193a14a1 100644 --- a/Package.swift +++ b/Package.swift @@ -146,6 +146,7 @@ let package = Package( .testTarget( name: "XToolTests", dependencies: [ + "XKit", "XToolSupport", ] ), diff --git a/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift b/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift index 13bbefd4..2dca4637 100644 --- a/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift +++ b/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift @@ -138,3 +138,9 @@ extension WirelessAccessoryEntitlement: EntitlementWithCapability { DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true) } } + +extension WiFiAwareEntitlement: EntitlementWithCapability { + var capability: DeveloperServicesCapability { + DeveloperServicesCapability(rawName: "WIFI_AWARE", isFree: false) + } +} diff --git a/Sources/XKit/Model/Entitlements/EntitlementTypes.swift b/Sources/XKit/Model/Entitlements/EntitlementTypes.swift index 16c8ab10..1d65a047 100644 --- a/Sources/XKit/Model/Entitlements/EntitlementTypes.swift +++ b/Sources/XKit/Model/Entitlements/EntitlementTypes.swift @@ -26,6 +26,7 @@ extension EntitlementContainer { SiriKitEntitlement.self, InterAppAudioEntitlement.self, WirelessAccessoryEntitlement.self, + WiFiAwareEntitlement.self, HomeKitEntitlement.self, HealthKitEntitlement.self, ] @@ -155,6 +156,21 @@ public struct WirelessAccessoryEntitlement: Entitlement, RawRepresentable { public init(rawValue: Bool) { self.rawValue = rawValue } } +public struct WiFiAwareEntitlement: Entitlement, RawRepresentable { + public static let identifier = "com.apple.developer.wifi-aware" + + public var rawValue: [String] + public init(rawValue: [String]) { self.rawValue = rawValue } + + public init(from decoder: Decoder) throws { + rawValue = try decoder.singleValueContainer().decode([String].self) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValue) + } +} + public struct HomeKitEntitlement: Entitlement, RawRepresentable { public static let identifier = "com.apple.developer.homekit" diff --git a/Tests/XToolTests/WiFiAwareEntitlementTests.swift b/Tests/XToolTests/WiFiAwareEntitlementTests.swift new file mode 100644 index 00000000..574a9166 --- /dev/null +++ b/Tests/XToolTests/WiFiAwareEntitlementTests.swift @@ -0,0 +1,39 @@ +import Foundation +import Testing +@testable import XKit + +@Test func wifiAwareEntitlementMapsToDeveloperCapability() throws { + let plist = """ + + + + + com.apple.developer.wifi-aware + + Publish + Subscribe + + + + """ + + let entitlements = try PropertyListDecoder().decode( + Entitlements.self, + from: Data(plist.utf8) + ) + let wifiAware = try #require( + entitlements.entitlements().compactMap { $0 as? WiFiAwareEntitlement }.first + ) + + #expect(wifiAware.rawValue == ["Publish", "Subscribe"]) + #expect(wifiAware.capability.capabilityType.value1 == nil) + #expect(wifiAware.capability.capabilityType.value2 == "WIFI_AWARE") + #expect(wifiAware.capability.settings == nil) + #expect(!wifiAware.capability.isFree) + + let encoded = try PropertyListEncoder().encode(entitlements) + let dictionary = try #require( + PropertyListSerialization.propertyList(from: encoded, format: nil) as? [String: Any] + ) + #expect(dictionary[WiFiAwareEntitlement.identifier] as? [String] == ["Publish", "Subscribe"]) +}