From 5a7fa843fd2ea77e9670af053f83a05bcc1f4324 Mon Sep 17 00:00:00 2001 From: Blake Oliver Date: Thu, 9 Apr 2026 01:20:32 -0600 Subject: [PATCH] Add app distribution detection and bump remoteFormEvent method ID - Add `AppDistribution` enum to `AppInfo.swift` that detects simulator, development, TestFlight, Ad Hoc, and App Store builds at runtime - Display distribution type in the settings footer version label - Bump `remoteFormEvent` server method ID from 20 to 21 (comment range updated to 9..20 accordingly) This fixes the client to work with the game server again and allows it to determine the install method. --- KDChat/AppInfo.swift | 29 +++++++++++++++++++++++++++ KDChat/Networking/ProtocolTypes.swift | 4 ++-- KDChat/Views/SettingsView.swift | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/KDChat/AppInfo.swift b/KDChat/AppInfo.swift index d52c6e8..e1219bb 100644 --- a/KDChat/AppInfo.swift +++ b/KDChat/AppInfo.swift @@ -4,4 +4,33 @@ enum AppInfo { static let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? "KDChat" static let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "–" static let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "–" + static let distribution = AppDistribution.current + static let testFlightURL: URL? = nil // TODO: set when TestFlight is configured +} + +enum AppDistribution: String { + case development = "Development" + case simulator = "Simulator" + case testFlight = "TestFlight" + case appStore = "App Store" + case adHoc = "Ad Hoc" + + static var current: AppDistribution { + #if targetEnvironment(simulator) + return .simulator + #else + #if DEBUG + return .development + #else + if let receiptURL = Bundle.main.appStoreReceiptURL, + receiptURL.lastPathComponent == "sandboxReceipt" { + return .testFlight + } + if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil { + return .adHoc + } + return .appStore + #endif + #endif + } } diff --git a/KDChat/Networking/ProtocolTypes.swift b/KDChat/Networking/ProtocolTypes.swift index ea37244..74dc91e 100644 --- a/KDChat/Networking/ProtocolTypes.swift +++ b/KDChat/Networking/ProtocolTypes.swift @@ -12,8 +12,8 @@ enum ServerMethod: Int32 { case leaveGame = 5 // 6 = TimeSync, 7 = RequestProfile case directMessage = 8 - // 9..19 = game-specific methods - case remoteFormEvent = 20 + // 9..20 = game-specific methods + case remoteFormEvent = 21 } // MARK: - Client Methods (server -> client) diff --git a/KDChat/Views/SettingsView.swift b/KDChat/Views/SettingsView.swift index 660002e..9048947 100644 --- a/KDChat/Views/SettingsView.swift +++ b/KDChat/Views/SettingsView.swift @@ -115,7 +115,7 @@ struct SettingsView: View { } Section { - Text("\(AppInfo.name) \(AppInfo.version) (\(AppInfo.build))") + Text("\(AppInfo.name) \(AppInfo.version) (\(AppInfo.build)) \(AppInfo.distribution.rawValue)") .foregroundStyle(.secondary) .frame(maxWidth: .infinity, alignment: .center) }