Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ let package = Package(
.testTarget(
name: "XToolTests",
dependencies: [
"XKit",
"XToolSupport",
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,9 @@ extension WirelessAccessoryEntitlement: EntitlementWithCapability {
DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true)
}
}

extension WiFiAwareEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(rawName: "WIFI_AWARE", isFree: false)
}
}
16 changes: 16 additions & 0 deletions Sources/XKit/Model/Entitlements/EntitlementTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension EntitlementContainer {
SiriKitEntitlement.self,
InterAppAudioEntitlement.self,
WirelessAccessoryEntitlement.self,
WiFiAwareEntitlement.self,
HomeKitEntitlement.self,
HealthKitEntitlement.self,
]
Expand Down Expand Up @@ -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"

Expand Down
39 changes: 39 additions & 0 deletions Tests/XToolTests/WiFiAwareEntitlementTests.swift
Original file line number Diff line number Diff line change
@@ -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"])
}