diff --git a/apps/ios/Shared/ContentView.swift b/apps/ios/Shared/ContentView.swift index 00cc25c1d2..7adf7a0435 100644 --- a/apps/ios/Shared/ContentView.swift +++ b/apps/ios/Shared/ContentView.swift @@ -430,19 +430,27 @@ struct ContentView: View { let m = ChatModel.shared if let url = m.appOpenUrl { m.appOpenUrl = nil - dismissAllSheets() { - var path = url.path - if (path == "/contact" || path == "/invitation" || path == "/a" || path == "/c" || path == "/g" || path == "/i") { - path.removeFirst() - let link = url.absoluteString.replacingOccurrences(of: "///\(path)", with: "/\(path)") - planAndConnect( - link, - theme: theme, - dismiss: false - ) - } else { - AlertManager.shared.showAlert(Alert(title: Text("Error: URL is invalid"))) - } + connectViaUrl_(url) + } else if let url = m.appOpenUrlLater, AppChatState.shared.value == .active, scenePhase == .active { + // correcting branch in case .onChange(of: scenePhase) in SimpleXApp doesn't trigger and transfer appOpenUrlLater into appOpenUrl + m.appOpenUrlLater = nil + connectViaUrl_(url) + } + } + + func connectViaUrl_(_ url: URL) { + dismissAllSheets() { + var path = url.path + if (path == "/contact" || path == "/invitation" || path == "/a" || path == "/c" || path == "/g" || path == "/i") { + path.removeFirst() + let link = url.absoluteString.replacingOccurrences(of: "///\(path)", with: "/\(path)") + planAndConnect( + link, + theme: theme, + dismiss: false + ) + } else { + AlertManager.shared.showAlert(Alert(title: Text("Error: URL is invalid"))) } } } diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index a08f70fd53..e5fd6362a3 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -385,6 +385,7 @@ final class ChatModel: ObservableObject { @Published var userAddress: UserContactLink? @Published var chatItemTTL: ChatItemTTL = .none @Published var appOpenUrl: URL? + @Published var appOpenUrlLater: URL? @Published var deviceToken: DeviceToken? @Published var savedToken: DeviceToken? @Published var tokenRegistered = false diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 5fbdafe19f..e1a6bb61e8 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -19,7 +19,6 @@ struct SimpleXApp: App { @Environment(\.scenePhase) var scenePhase @State private var enteredBackgroundAuthenticated: TimeInterval? = nil - @State private var appOpenUrlLater: URL? init() { DispatchQueue.global(qos: .background).sync { @@ -46,7 +45,7 @@ struct SimpleXApp: App { if AppChatState.shared.value == .active { chatModel.appOpenUrl = url } else { - appOpenUrlLater = url + chatModel.appOpenUrlLater = url } } .onAppear() { @@ -98,15 +97,15 @@ struct SimpleXApp: App { if !chatModel.showCallView && !CallController.shared.hasActiveCalls() { await updateCallInvitations() } - if let url = appOpenUrlLater { + if let url = chatModel.appOpenUrlLater { await MainActor.run { - appOpenUrlLater = nil + chatModel.appOpenUrlLater = nil chatModel.appOpenUrl = url } } } - } else if let url = appOpenUrlLater { - appOpenUrlLater = nil + } else if let url = chatModel.appOpenUrlLater { + chatModel.appOpenUrlLater = nil chatModel.appOpenUrl = url } }