mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 04:45:20 +00:00
Fix macOS thread checker warning
- Move all app state checks inside DispatchQueue.main.async - Ensures NSApplication.isActive is only accessed from main thread - Prevents thread checker warnings on macOS
This commit is contained in:
@@ -30,19 +30,7 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendLocalNotification(title: String, body: String, identifier: String) {
|
func sendLocalNotification(title: String, body: String, identifier: String) {
|
||||||
// Create notification content first (thread-safe)
|
// Everything must be on main thread to check app state
|
||||||
let content = UNMutableNotificationContent()
|
|
||||||
content.title = title
|
|
||||||
content.body = body
|
|
||||||
content.sound = .default
|
|
||||||
|
|
||||||
let request = UNNotificationRequest(
|
|
||||||
identifier: identifier,
|
|
||||||
content: content,
|
|
||||||
trigger: nil // Deliver immediately
|
|
||||||
)
|
|
||||||
|
|
||||||
// Check app state on main thread and send notification
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
guard UIApplication.shared.applicationState != .active else {
|
guard UIApplication.shared.applicationState != .active else {
|
||||||
@@ -58,7 +46,18 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// App is in background/inactive, send notification
|
// App is in background/inactive, create and send notification
|
||||||
|
let content = UNMutableNotificationContent()
|
||||||
|
content.title = title
|
||||||
|
content.body = body
|
||||||
|
content.sound = .default
|
||||||
|
|
||||||
|
let request = UNNotificationRequest(
|
||||||
|
identifier: identifier,
|
||||||
|
content: content,
|
||||||
|
trigger: nil // Deliver immediately
|
||||||
|
)
|
||||||
|
|
||||||
UNUserNotificationCenter.current().add(request) { error in
|
UNUserNotificationCenter.current().add(request) { error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("📱 Error sending local notification: \(error)")
|
print("📱 Error sending local notification: \(error)")
|
||||||
|
|||||||
Reference in New Issue
Block a user