Skip to content

Commit b0ce2d1

Browse files
bjorkertmarionbarker
authored andcommitted
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.
1 parent a1e8e95 commit b0ce2d1

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

LoopFollow/Application/AppDelegate.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,21 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
263263
willPresent notification: UNNotification,
264264
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
265265
{
266-
// Log the notification
267-
let userInfo = notification.request.content.userInfo
268-
let userInfoKeys = userInfo.keys.compactMap { $0 as? String }.sorted()
269-
LogManager.shared.log(category: .general, message: "Will present notification: keys=\(userInfoKeys)")
266+
let content = notification.request.content
267+
let userInfoKeys = content.userInfo.keys.compactMap { $0 as? String }.sorted()
268+
LogManager.shared.log(
269+
category: .general,
270+
message: "Will present notification: keys=\(userInfoKeys), interruption=\(content.interruptionLevel.rawValue), title=\(content.title.isEmpty ? "empty" : "set"), body=\(content.body.isEmpty ? "empty" : "set")"
271+
)
272+
273+
// Suppress notifications iOS routes here that we never intended to surface:
274+
// the Live Activity push-to-start uses interruption-level: passive with empty
275+
// title/body and must not produce a banner or sound when LF is foregrounded.
276+
if content.interruptionLevel == .passive || (content.title.isEmpty && content.body.isEmpty) {
277+
completionHandler([])
278+
return
279+
}
270280

271-
// Show the notification even when app is in foreground
272281
completionHandler([.banner, .sound, .badge])
273282
}
274283
}

0 commit comments

Comments
 (0)