From a80a128b639f86d8b1ff9d4f49797b28450db882 Mon Sep 17 00:00:00 2001 From: Johan Degraeve Date: Sat, 18 Jun 2022 00:12:09 +0200 Subject: [PATCH] fix bug : Volume test iOS sound wasn't working anymore, seems since iOS 14, see https://stackoverflow.com/questions/69023854/ios-15-notification-sounds-are-not-playing-for-foreground-notifications and https://developer.apple.com/forums/thread/700884 ("Displaying" sound only notifications is no longer possible.) The solution is - to add a dummy text and body in the test notification - to add .list if iOS 14 or higher --- .../Root View Controller/RootViewController.swift | 7 ++++++- .../SettingsViewAlertSettingsViewModel.swift | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/xdrip/View Controllers/Root View Controller/RootViewController.swift b/xdrip/View Controllers/Root View Controller/RootViewController.swift index ea792e64..e0a779e4 100644 --- a/xdrip/View Controllers/Root View Controller/RootViewController.swift +++ b/xdrip/View Controllers/Root View Controller/RootViewController.swift @@ -2982,7 +2982,12 @@ extension RootViewController: UNUserNotificationCenterDelegate { } else if notification.request.identifier == ConstantsNotifications.notificationIdentifierForVolumeTest { // user is testing iOS Sound volume in the settings. Only the sound should be played, the alert itself will not be shown - completionHandler([.sound]) + if #available(iOS 14.0, *) { + completionHandler([.sound, .list]) + } else { + // Fallback on earlier versions + completionHandler([.sound]) + } } else if notification.request.identifier == ConstantsNotifications.notificationIdentifierForxCGMTransmitterDelegatexDripError { diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift index b6e57cbb..26ecc9af 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift @@ -71,9 +71,9 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol { // define and set the content let content = UNMutableNotificationContent() - // body and title will not be shown, so contents can be empty - content.body = "" - content.title = "" + // body and title will not be shown, because app is in the foreground + content.body = "will not be shown" + content.title = "will not be shown" // sound content.sound = UNNotificationSound.init(named: UNNotificationSoundName.init("xdripalert.aif")) // notification request