From 9166fcc59b58abaf721a2ed3105bae4190c4fa00 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Sat, 27 Feb 2021 18:06:06 +0100 Subject: [PATCH] feat: Handle critical notifications in payload extension, due to FCM legacy api limitation --- .../EQNNotificationService/NotificationService.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/EQNNotificationService/NotificationService.m b/Sources/EQNNotificationService/NotificationService.m index 4ccd40e..4e48350 100644 --- a/Sources/EQNNotificationService/NotificationService.m +++ b/Sources/EQNNotificationService/NotificationService.m @@ -28,7 +28,6 @@ static NSString * const EQNSoundNotificationEQN = @"alert_sound.wav"; UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; content.title = [NSString localizedUserNotificationStringForKey:request.content.title arguments:nil]; content.body = [NSString localizedUserNotificationStringForKey:request.content.body arguments:nil]; - content.sound = [UNNotificationSound defaultSound]; self.bestAttemptContent.title = content.title; self.bestAttemptContent.body = content.body; @@ -44,9 +43,16 @@ static NSString * const EQNSoundNotificationEQN = @"alert_sound.wav"; NSString *iconName = @""; if ([notificationType isEqualToString:@"eqn"]) { - UNNotificationSound *sound = [UNNotificationSound soundNamed:EQNSoundNotificationEQN]; - self.bestAttemptContent.sound = sound; - + // !!WORKAROUND + // this is a workaround to use critical alerts with legacy FCM api + // when the server implementation will be migrated to Firebase v1 APIs, this could be removed + BOOL isCritical = [[userInfo objectForKey:@"critical"] boolValue]; + if (isCritical) { + self.bestAttemptContent.sound = [UNNotificationSound criticalSoundNamed:EQNSoundNotificationEQN withAudioVolume:1.0]; + } else { + self.bestAttemptContent.sound = [UNNotificationSound soundNamed:EQNSoundNotificationEQN]; + } + NSString *intensity = [userInfo objectForKey:@"intensity"]; switch ([intensity intValue]) { case 0: