diff --git a/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzNotificationSound.swift b/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzNotificationSound.swift index a326965e29..44ff495d90 100644 --- a/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzNotificationSound.swift +++ b/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzNotificationSound.swift @@ -2,6 +2,16 @@ import UserNotifications /// Applies the ordinary alert sound policy at the final service-extension handoff. public enum BuzzNotificationSound { + /// Creates the service extension's final handoff with the incoming APNs sound policy. + public static func makeHandoff( + originalSound: UNNotificationSound?, + contentHandler: @escaping (UNNotificationContent) -> Void + ) -> BuzzNotificationHandoff { + BuzzNotificationHandoff { content in + contentHandler(preparing(content, originalSound: originalSound)) + } + } + /// Preserves the incoming APNs sound, or adds the default when no sound exists. public static func preparing( _ content: UNNotificationContent, diff --git a/mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzNotificationSoundTests.swift b/mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzNotificationSoundTests.swift index 8551208840..60f33eec33 100644 --- a/mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzNotificationSoundTests.swift +++ b/mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzNotificationSoundTests.swift @@ -39,8 +39,8 @@ struct BuzzNotificationSoundTests { func `Final handoff applies sound to resolved and restricted content once`(allowed: Bool) { var delivered: [UNNotificationContent] = [] let original = UNMutableNotificationContent() - let handoff = BuzzNotificationHandoff { content in - delivered.append(BuzzNotificationSound.preparing(content, originalSound: original.sound)) + let handoff = BuzzNotificationSound.makeHandoff(originalSound: original.sound) { content in + delivered.append(content) } let resolved = UNMutableNotificationContent() resolved.title = "Sender" @@ -64,8 +64,8 @@ struct BuzzNotificationSoundTests { @Test func `Expiration receives sound before a late resolution is ignored`() { var delivered: [UNNotificationContent] = [] - let handoff = BuzzNotificationHandoff { content in - delivered.append(BuzzNotificationSound.preparing(content, originalSound: nil)) + let handoff = BuzzNotificationSound.makeHandoff(originalSound: nil) { content in + delivered.append(content) } for body in ["Reconnect to your relay now", "Resolved message"] { let content = UNMutableNotificationContent() diff --git a/mobile/ios/NotificationService/NotificationService.swift b/mobile/ios/NotificationService/NotificationService.swift index 5e83469fee..fb16bdf4d0 100644 --- a/mobile/ios/NotificationService/NotificationService.swift +++ b/mobile/ios/NotificationService/NotificationService.swift @@ -100,10 +100,9 @@ final class NotificationService: UNNotificationServiceExtension { withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void ) { resolvedScope = nil - let originalSound = request.content.sound - handoff = BuzzNotificationHandoff { content in - contentHandler(BuzzNotificationSound.preparing(content, originalSound: originalSound)) - } + handoff = BuzzNotificationSound.makeHandoff( + originalSound: request.content.sound, contentHandler: contentHandler + ) restrictedFallbackContent = Self.restrictedFallback(from: request.content) guard let content = request.content.mutableCopy() as? UNMutableNotificationContent else { finish(request.content)