Преглед изворни кода

Suppress silent passive notifications in willPresent handler (#655)

UNUserNotificationCenterDelegate.willPresent returned
[.banner, .sound, .badge] unconditionally, which meant any notification
iOS routed through this handler while the app was foregrounded produced
sound — including the Live Activity push-to-start payload, which is
intentionally silent (interruption-level: passive, empty title/body).

Now returns [] for passive notifications and for ones with empty
title/body. The four intentional alerts (renewal-failed, APNs
credentials missing, push-to-start token missing, alarms) all use
non-empty title/body and the default .active interruption level, so
they continue to surface.

Also expanded the willPresent log line with interruptionLevel and
title/body presence so future reports can confirm whether iOS routed
a given payload here.
Jonas Björkert пре 1 месец
родитељ
комит
b0ce2d1a67
1 измењених фајлова са 14 додато и 5 уклоњено
  1. 14 5
      LoopFollow/Application/AppDelegate.swift

+ 14 - 5
LoopFollow/Application/AppDelegate.swift

@@ -263,12 +263,21 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
                                 willPresent notification: UNNotification,
                                 withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
     {
-        // Log the notification
-        let userInfo = notification.request.content.userInfo
-        let userInfoKeys = userInfo.keys.compactMap { $0 as? String }.sorted()
-        LogManager.shared.log(category: .general, message: "Will present notification: keys=\(userInfoKeys)")
+        let content = notification.request.content
+        let userInfoKeys = content.userInfo.keys.compactMap { $0 as? String }.sorted()
+        LogManager.shared.log(
+            category: .general,
+            message: "Will present notification: keys=\(userInfoKeys), interruption=\(content.interruptionLevel.rawValue), title=\(content.title.isEmpty ? "empty" : "set"), body=\(content.body.isEmpty ? "empty" : "set")"
+        )
+
+        // Suppress notifications iOS routes here that we never intended to surface:
+        // the Live Activity push-to-start uses interruption-level: passive with empty
+        // title/body and must not produce a banner or sound when LF is foregrounded.
+        if content.interruptionLevel == .passive || (content.title.isEmpty && content.body.isEmpty) {
+            completionHandler([])
+            return
+        }
 
-        // Show the notification even when app is in foreground
         completionHandler([.banner, .sound, .badge])
     }
 }