From 4bf4435feb1dffd1eca210a055750ecfbe3fe882 Mon Sep 17 00:00:00 2001 From: Schwifty Date: Mon, 23 Mar 2026 03:47:27 +0000 Subject: [PATCH] fix: resolve false disconnect error at end of provisioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit succeed() was calling disconnectPeripheral() before completion(), so the disconnect delegate fired while writesCompleted was still false — causing the "Unexpected disconnect" error log even on successful provisions. Swapped order: signal completion first, then disconnect. Also removed the redundant provisioner.disconnect() in ScanView since succeed() already handles it. Co-Authored-By: Claude Opus 4.6 (1M context) --- PayfritBeacon/BeaconProvisioner.swift | 4 +++- PayfritBeacon/Views/ScanView.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PayfritBeacon/BeaconProvisioner.swift b/PayfritBeacon/BeaconProvisioner.swift index 7215149..5d2dee0 100644 --- a/PayfritBeacon/BeaconProvisioner.swift +++ b/PayfritBeacon/BeaconProvisioner.swift @@ -365,8 +365,10 @@ class BeaconProvisioner: NSObject, ObservableObject { isTerminating = true DebugLog.shared.log("BLE: Provisioning success!") state = .success - disconnectPeripheral() + // Signal completion BEFORE disconnecting — the disconnect delegate fires + // synchronously and ScanView needs writesCompleted=true before it sees it completion?(.success(macAddress: nil)) + disconnectPeripheral() cleanup() } diff --git a/PayfritBeacon/Views/ScanView.swift b/PayfritBeacon/Views/ScanView.swift index 4210268..64d4586 100644 --- a/PayfritBeacon/Views/ScanView.swift +++ b/PayfritBeacon/Views/ScanView.swift @@ -698,7 +698,7 @@ struct ScanView: View { try await provisioner.writeConfig(config) writesCompleted = true - provisioner.disconnect() + // No explicit disconnect needed — succeed() already disconnects try await APIClient.shared.registerBeaconHardware( businessId: business.id,