Skip to content

Commit 6b31bf4

Browse files
authored
[LOOP-4863] updated handling of notification permissions (#661)
* updated handling of notification permissions * clean up
1 parent 236e87f commit 6b31bf4

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

Loop/Managers/AlertPermissionsChecker.swift

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class AlertPermissionsChecker: ObservableObject {
7575
}
7676
if #available(iOS 15.0, *) {
7777
newSettings.scheduledDeliveryEnabled = settings.scheduledDeliverySetting == .enabled
78-
newSettings.timeSensitiveNotificationsDisabled = settings.alertSetting != .disabled && settings.timeSensitiveSetting == .disabled
78+
newSettings.timeSensitiveDisabled = settings.alertSetting != .disabled && settings.timeSensitiveSetting == .disabled
7979
}
8080
self.notificationCenterSettings = newSettings
8181
completion?()
@@ -110,81 +110,95 @@ extension AlertPermissionsChecker {
110110
enum UnsafeNotificationPermissionAlert: Hashable, CaseIterable {
111111
case notificationsDisabled
112112
case criticalAlertsDisabled
113-
case timeSensitiveNotificationsDisabled
113+
case timeSensitiveDisabled
114+
case criticalAlertsAndNotificationDisabled
115+
case criticalAlertsAndTimeSensitiveDisabled
114116

115117
var alertTitle: String {
116118
switch self {
117-
case .notificationsDisabled:
118-
NSLocalizedString("Turn On Critical Alerts and Other Safety Notifications", comment: "Notifications disabled alert title")
119+
case .criticalAlertsAndNotificationDisabled, .criticalAlertsAndTimeSensitiveDisabled:
120+
NSLocalizedString("Turn On Critical Alerts and Time Sensitive Notifications", comment: "Both Critical Alerts and Time Sensitive Notifications disabled alert title")
119121
case .criticalAlertsDisabled:
120122
NSLocalizedString("Turn On Critical Alerts", comment: "Critical alerts disabled alert title")
121-
case .timeSensitiveNotificationsDisabled:
123+
case .timeSensitiveDisabled, .notificationsDisabled:
122124
NSLocalizedString("Turn On Time Sensitive Notifications ", comment: "Time sensitive notifications disabled alert title")
123125
}
124126
}
125127

126128
var notificationTitle: String {
127129
switch self {
128-
case .notificationsDisabled:
129-
NSLocalizedString("Turn On Critical Alerts and other safety notifications", comment: "Notifications disabled notification title")
130+
case .criticalAlertsAndNotificationDisabled, .criticalAlertsAndTimeSensitiveDisabled:
131+
NSLocalizedString("Turn On Critical Alerts and Time Sensitive Notifications", comment: "Both Critical Alerts and Time Sensitive Notifications disabled notification title")
130132
case .criticalAlertsDisabled:
131133
NSLocalizedString("Turn On Critical Alerts", comment: "Critical alerts disabled notification title")
132-
case .timeSensitiveNotificationsDisabled:
134+
case .timeSensitiveDisabled, .notificationsDisabled:
133135
NSLocalizedString("Turn On Time Sensitive Notifications", comment: "Time sensitive notifications disabled alert title")
134136
}
135137
}
136138

137139
var bannerTitle: String {
138140
switch self {
139-
case .notificationsDisabled:
140-
NSLocalizedString("Critical Alerts and other safety notifications are turned OFF", comment: "Notifications disabled banner title")
141+
case .criticalAlertsAndNotificationDisabled, .criticalAlertsAndTimeSensitiveDisabled:
142+
NSLocalizedString("Critical Alerts and Time Sensitive Notifications are turned OFF", comment: "Both Critical Alerts and Time Sensitive Notifications disabled banner title")
141143
case .criticalAlertsDisabled:
142-
NSLocalizedString("Critical alerts are turned OFF", comment: "Critical alerts disabled banner title")
143-
case .timeSensitiveNotificationsDisabled:
144+
NSLocalizedString("Critical Alerts are turned OFF", comment: "Critical alerts disabled banner title")
145+
case .timeSensitiveDisabled, .notificationsDisabled:
144146
NSLocalizedString("Time Sensitive Alerts are turned OFF", comment: "Time sensitive notifications disabled banner title")
145147
}
146148
}
147149

148150
var alertBody: String {
149151
switch self {
150152
case .notificationsDisabled:
151-
NSLocalizedString("Critical Alerts and other safety notifications are turned off. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Notifications and Critical Alerts are turned ON.", comment: "Notifications disabled alert body")
153+
NSLocalizedString("Time Sensitive Alerts are turned OFF. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Notifications are turned ON.", comment: "Notifications disabled alert body")
154+
case .criticalAlertsAndNotificationDisabled:
155+
NSLocalizedString("Critical Alerts and Time Sensitive Notifications are turned off. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Notifications and Critical Alerts are turned ON.", comment: "Both Notifications and Critical Alerts disabled alert body")
156+
case .criticalAlertsAndTimeSensitiveDisabled:
157+
NSLocalizedString("Critical Alerts and Time Sensitive Notifications are turned off. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Critical Alerts and Time Sensitive Notifications are turned ON.", comment: "Both Critical Alerts and Time Sensitive Notifications disabled alert body")
152158
case .criticalAlertsDisabled:
153159
NSLocalizedString("Critical Alerts are turned off. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Critical Alerts are turned ON.", comment: "Critical alerts disabled alert body")
154-
case .timeSensitiveNotificationsDisabled:
160+
case .timeSensitiveDisabled:
155161
NSLocalizedString("Time Sensitive Alerts are turned OFF. You may not get sound, visual or vibration alerts regarding critical safety information.\n\nTo fix the issue, tap ‘Settings’ and make sure Time Sensitive Notifications are turned ON.", comment: "Time sensitive notifications disabled alert body")
156162
}
157163
}
158164

159165
var notificationBody: String {
160166
switch self {
161-
case .notificationsDisabled:
162-
NSLocalizedString("Critical Alerts and other safety notifications are turned OFF. Go to the App to fix the issue now.", comment: "Notifications disabled notification body")
167+
case .criticalAlertsAndNotificationDisabled, .criticalAlertsAndTimeSensitiveDisabled:
168+
NSLocalizedString("Critical Alerts and Time Sensitive Notifications are turned OFF. Go to the App to fix the issue now.", comment: "Both Critical Alerts and Time Sensitive Notifications disabled notification body")
163169
case .criticalAlertsDisabled:
164170
NSLocalizedString("Critical Alerts are turned OFF. Go to the App to fix the issue now.", comment: "Critical alerts disabled notification body")
165-
case .timeSensitiveNotificationsDisabled:
171+
case .timeSensitiveDisabled, .notificationsDisabled:
166172
NSLocalizedString("Time Sensitive notifications are turned OFF. Go to the App to fix the issue now.", comment: "Time sensitive notifications disabled notification body")
167173
}
168174
}
169175

170176
var bannerBody: String {
171177
switch self {
172178
case .notificationsDisabled:
173-
NSLocalizedString("Fix now by turning Notifications and Critical Alerts ON.", comment: "Notifications disabled banner body")
179+
NSLocalizedString("Fix now by turning Notifications ON.", comment: "Notifications disabled banner body")
180+
case .criticalAlertsAndNotificationDisabled:
181+
NSLocalizedString("Fix now by turning Notifications and Critical Alerts ON.", comment: "Both Critical Alerts and Notifications disabled banner body")
182+
case .criticalAlertsAndTimeSensitiveDisabled:
183+
NSLocalizedString("Fix now by turning Critical Alerts and Time Sensitive Notifications ON.", comment: "Both Critical Alerts and Time Sensitive Notifications disabled banner body")
174184
case .criticalAlertsDisabled:
175185
NSLocalizedString("Fix now by turning Critical Alerts ON.", comment: "Critical alerts disabled banner body")
176-
case .timeSensitiveNotificationsDisabled:
177-
NSLocalizedString("Fix now by turning Time Sensitive alerts ON.", comment: "Time sensitive notifications disabled banner body")
186+
case .timeSensitiveDisabled:
187+
NSLocalizedString("Fix now by turning Time Sensitive Notifications ON.", comment: "Time sensitive notifications disabled banner body")
178188
}
179189
}
180190

181191
var alertIdentifier: LoopKit.Alert.Identifier {
182192
switch self {
183193
case .notificationsDisabled:
184194
Alert.Identifier(managerIdentifier: "LoopAppManager", alertIdentifier: "unsafeNotificationPermissionsAlert")
195+
case .criticalAlertsAndNotificationDisabled:
196+
Alert.Identifier(managerIdentifier: "LoopAppManager", alertIdentifier: "unsafeCriticalAlertAndNotificationPermissionsAlert")
197+
case .criticalAlertsAndTimeSensitiveDisabled:
198+
Alert.Identifier(managerIdentifier: "LoopAppManager", alertIdentifier: "unsafeCriticalAlertAndTimeSensitivePermissionsAlert")
185199
case .criticalAlertsDisabled:
186200
Alert.Identifier(managerIdentifier: "LoopAppManager", alertIdentifier: "unsafeCrititalAlertPermissionsAlert")
187-
case .timeSensitiveNotificationsDisabled:
201+
case .timeSensitiveDisabled:
188202
Alert.Identifier(managerIdentifier: "LoopAppManager", alertIdentifier: "unsafeTimeSensitiveNotificationPermissionsAlert")
189203
}
190204
}
@@ -208,12 +222,16 @@ extension AlertPermissionsChecker {
208222

209223
init?(permissions: NotificationCenterSettingsFlags) {
210224
switch permissions {
211-
case .notificationsDisabled, NotificationCenterSettingsFlags(rawValue: 3), NotificationCenterSettingsFlags(rawValue: 5):
225+
case .notificationsDisabled:
212226
self = .notificationsDisabled
213-
case .criticalAlertsDisabled, NotificationCenterSettingsFlags(rawValue: 6):
227+
case .timeSensitiveDisabled, NotificationCenterSettingsFlags(rawValue: 5):
228+
self = .timeSensitiveDisabled
229+
case .criticalAlertsDisabled:
214230
self = .criticalAlertsDisabled
215-
case .timeSensitiveNotificationsDisabled:
216-
self = .timeSensitiveNotificationsDisabled
231+
case NotificationCenterSettingsFlags(rawValue: 3):
232+
self = .criticalAlertsAndNotificationDisabled
233+
case NotificationCenterSettingsFlags(rawValue: 6):
234+
self = .criticalAlertsAndTimeSensitiveDisabled
217235
default:
218236
return nil
219237
}
@@ -277,10 +295,10 @@ struct NotificationCenterSettingsFlags: OptionSet {
277295
static let none = NotificationCenterSettingsFlags([])
278296
static let notificationsDisabled = NotificationCenterSettingsFlags(rawValue: 1 << 0)
279297
static let criticalAlertsDisabled = NotificationCenterSettingsFlags(rawValue: 1 << 1)
280-
static let timeSensitiveNotificationsDisabled = NotificationCenterSettingsFlags(rawValue: 1 << 2)
298+
static let timeSensitiveDisabled = NotificationCenterSettingsFlags(rawValue: 1 << 2)
281299
static let scheduledDeliveryEnabled = NotificationCenterSettingsFlags(rawValue: 1 << 3)
282300

283-
static let requiresRiskMitigation: NotificationCenterSettingsFlags = [ .notificationsDisabled, .criticalAlertsDisabled, .timeSensitiveNotificationsDisabled ]
301+
static let requiresRiskMitigation: NotificationCenterSettingsFlags = [ .notificationsDisabled, .criticalAlertsDisabled, .timeSensitiveDisabled ]
284302
}
285303

286304
extension NotificationCenterSettingsFlags {
@@ -300,12 +318,12 @@ extension NotificationCenterSettingsFlags {
300318
update(.criticalAlertsDisabled, newValue)
301319
}
302320
}
303-
var timeSensitiveNotificationsDisabled: Bool {
321+
var timeSensitiveDisabled: Bool {
304322
get {
305-
contains(.timeSensitiveNotificationsDisabled)
323+
contains(.timeSensitiveDisabled)
306324
}
307325
set {
308-
update(.timeSensitiveNotificationsDisabled, newValue)
326+
update(.timeSensitiveDisabled, newValue)
309327
}
310328
}
311329
var scheduledDeliveryEnabled: Bool {

Loop/Views/NotificationsCriticalAlertPermissionsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ extension NotificationsCriticalAlertPermissionsView {
118118
HStack {
119119
Text("Time Sensitive Notifications", comment: "Time Sensitive Status text")
120120
Spacer()
121-
onOff(!checker.notificationCenterSettings.timeSensitiveNotificationsDisabled)
121+
onOff(!checker.notificationCenterSettings.timeSensitiveDisabled)
122122
}
123123
}
124124

0 commit comments

Comments
 (0)