From 3d3c7118857d4f438a905a4b84500f2f2c6cdd98 Mon Sep 17 00:00:00 2001 From: jack Date: Tue, 22 Jul 2025 16:47:04 +0200 Subject: [PATCH] Remove app state checks to fix thread issues - Completely remove UIApplication/NSApplication state checks - Let NotificationDelegate handle foreground presentation - All notifications now sent regardless of app state - Fixes all thread checker warnings --- bitchat/Services/NotificationService.swift | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/bitchat/Services/NotificationService.swift b/bitchat/Services/NotificationService.swift index c1ea0207..b5fa4170 100644 --- a/bitchat/Services/NotificationService.swift +++ b/bitchat/Services/NotificationService.swift @@ -30,23 +30,9 @@ class NotificationService { } func sendLocalNotification(title: String, body: String, identifier: String) { - // Everything must be on main thread to check app state + // For now, skip app state check entirely to avoid thread issues + // The NotificationDelegate will handle foreground presentation DispatchQueue.main.async { - #if os(iOS) - guard UIApplication.shared.applicationState != .active else { - // App is active/foreground, skipping notification - print("📱 Skipping notification - app is in foreground") - return - } - #elseif os(macOS) - guard !NSApplication.shared.isActive else { - // App is active/foreground, skipping notification - print("📱 Skipping notification - app is in foreground") - return - } - #endif - - // App is in background/inactive, create and send notification let content = UNMutableNotificationContent() content.title = title content.body = body @@ -61,6 +47,8 @@ class NotificationService { UNUserNotificationCenter.current().add(request) { error in if let error = error { print("📱 Error sending local notification: \(error)") + } else { + print("📱 Local notification sent: \(title)") } } }