From 9aaabfc57335b508a890270077a9507d78339540 Mon Sep 17 00:00:00 2001 From: Stephen B <158498287+StephenDev0@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:57:19 -0400 Subject: [PATCH 1/2] Handle InvalidHostID error --- StikJIT/StikJITApp.swift | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/StikJIT/StikJITApp.swift b/StikJIT/StikJITApp.swift index 43aa666e..54e0c442 100644 --- a/StikJIT/StikJITApp.swift +++ b/StikJIT/StikJITApp.swift @@ -538,13 +538,10 @@ struct HeartbeatApp: App { isLoading2 = false timer.invalidate() } else { - if let error { - if error == -9 { // InvalidHostID is -9 - isPairing = true - } else { - startHeartbeatInBackground() - } - self.error = nil + if !isPairing() { + isPairing = true + } else { + startHeartbeatInBackground() } } } @@ -794,8 +791,9 @@ func isPairing() -> Bool { var pairingFile: IdevicePairingFile? let err = idevice_pairing_file_read(pairingpath, &pairingFile) if let err { - print("Failed to read pairing file: \(err.pointee.code)") - if err.pointee.code == -9 { // InvalidHostID is -9 + let message = err.pointee.message != nil ? String(cString: err.pointee.message) : "" + print("Failed to read pairing file: \(message)") + if message == "InvalidHostID" { return false } return false @@ -816,18 +814,18 @@ func startHeartbeatInBackground() { } else { print("Error: \(message ?? "") (Code: \(result))") DispatchQueue.main.async { - // Special handling for InvalidHostID error (code -9) - if result == -9 { + // Special handling for InvalidHostID error + if message == "InvalidHostID" { do { try FileManager.default.removeItem(at: URL.documentsDirectory.appendingPathComponent("pairingFile.plist")) - print("Removed invalid pairing file") + print("Removed pairing file with invalid host ID") } catch { - print("Error removing invalid pairing file: \(error)") + print("Error removing invalid host ID pairing file: \(error)") } - + showAlert( - title: "Invalid Pairing File", - message: "The pairing file is invalid or expired. Please select a new pairing file.", + title: "Invalid Host ID", + message: "The host ID in the pairing file is invalid or expired. Please select a new pairing file.", showOk: true, showTryAgain: false, primaryButtonText: "Select New File" From 3843d923b4d7c78f575b1b24dfb0068cd5efe9d0 Mon Sep 17 00:00:00 2001 From: Stephen B <158498287+StephenDev0@users.noreply.github.com> Date: Mon, 21 Jul 2025 21:59:05 -0400 Subject: [PATCH 2/2] Fix InvalidHostID handling and clarify isPairing calls --- StikJIT/StikJITApp.swift | 4 ++-- StikJIT/Views/HomeView.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/StikJIT/StikJITApp.swift b/StikJIT/StikJITApp.swift index 54e0c442..7a4bddc9 100644 --- a/StikJIT/StikJITApp.swift +++ b/StikJIT/StikJITApp.swift @@ -538,7 +538,7 @@ struct HeartbeatApp: App { isLoading2 = false timer.invalidate() } else { - if !isPairing() { + if !StikDebug.isPairing() { isPairing = true } else { startHeartbeatInBackground() @@ -752,7 +752,7 @@ class MountingProgress: ObservableObject { self.coolisMounted = isMounted() let pairingpath = URL.documentsDirectory.appendingPathComponent("pairingFile.plist").path - if isPairing(), !isMounted() { + if StikDebug.isPairing(), !isMounted() { if let mountingThread = mountingThread { mountingThread.cancel() self.mountingThread = nil diff --git a/StikJIT/Views/HomeView.swift b/StikJIT/Views/HomeView.swift index 49d2a5b0..40e3b84c 100644 --- a/StikJIT/Views/HomeView.swift +++ b/StikJIT/Views/HomeView.swift @@ -404,7 +404,7 @@ struct HomeView: View { // If the file exists, check if it's valid if fileExists { // Check if the pairing file is valid - let isValid = isPairing() + let isValid = StikDebug.isPairing() pairingFileExists = isValid } else { pairingFileExists = false