Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Support wifi-aware entitlement (#240)

SuperKenVery8f118445538b
diff --git a/Package.swift b/Package.swift
index 8ea98c7..193a14a 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 13bbefd..2dca463 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 16c8ab1..1d65a04 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 0000000..574a916
--- /dev/null
+++ b/Tests/XToolTests/WiFiAwareEntitlementTests.swift
@@ -0,0 +1,39 @@
+import Foundation
+import Testing
+@testable import XKit
+
+@Test func wifiAwareEntitlementMapsToDeveloperCapability() throws {
+ let plist = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+ <key>com.apple.developer.wifi-aware</key>
+ <array>
+ <string>Publish</string>
+ <string>Subscribe</string>
+ </array>
+ </dict>
+ </plist>
+ """
+
+ 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"])
+}