@@ -124,33 +124,44 @@ struct NotificationManager {
124124 }
125125
126126 static func sendPumpBatteryLowNotification( ) {
127- let notification = UILocalNotification ( )
127+ let notification = UNMutableNotificationContent ( )
128+
129+ notification. title = NSLocalizedString ( " Pump Battery Low " , comment: " The notification title for a low pump battery " )
130+ notification. body = NSLocalizedString ( " Change the pump battery immediately " , comment: " The notification alert describing a low pump battery " )
131+ notification. sound = UNNotificationSound . default ( )
132+ notification. categoryIdentifier = Category . PumpBatteryLow. rawValue
128133
129- notification. alertTitle = NSLocalizedString ( " Pump Battery Low " , comment: " The notification title for a low pump battery " )
130- notification. alertBody = NSLocalizedString ( " Change the pump battery immediately " , comment: " The notification alert describing a low pump battery " )
131- notification. soundName = UILocalNotificationDefaultSoundName
132- notification. category = Category . PumpBatteryLow. rawValue
134+ let request = UNNotificationRequest (
135+ identifier: Category . PumpBatteryLow. rawValue,
136+ content: notification,
137+ trigger: nil
138+ )
133139
134- UIApplication . shared . presentLocalNotificationNow ( notification )
140+ UNUserNotificationCenter . current ( ) . add ( request )
135141 }
136142
137143 static func sendPumpReservoirEmptyNotification( ) {
138- let notification = UILocalNotification ( )
144+ let notification = UNMutableNotificationContent ( )
139145
140- notification. alertTitle = NSLocalizedString ( " Pump Reservoir Empty " , comment: " The notification title for an empty pump reservoir " )
141- notification. alertBody = NSLocalizedString ( " Change the pump reservoir now " , comment: " The notification alert describing an empty pump reservoir " )
142- notification. soundName = UILocalNotificationDefaultSoundName
143- notification. category = Category . PumpReservoirEmpty. rawValue
146+ notification. title = NSLocalizedString ( " Pump Reservoir Empty " , comment: " The notification title for an empty pump reservoir " )
147+ notification. body = NSLocalizedString ( " Change the pump reservoir now " , comment: " The notification alert describing an empty pump reservoir " )
148+ notification. sound = UNNotificationSound . default ( )
149+ notification. categoryIdentifier = Category . PumpReservoirEmpty. rawValue
144150
145- // TODO: Add an action to Suspend the pump
151+ let request = UNNotificationRequest (
152+ // Not a typo: this should replace any pump reservoir low notifications
153+ identifier: Category . PumpReservoirLow. rawValue,
154+ content: notification,
155+ trigger: nil
156+ )
146157
147- UIApplication . shared . presentLocalNotificationNow ( notification )
158+ UNUserNotificationCenter . current ( ) . add ( request )
148159 }
149160
150161 static func sendPumpReservoirLowNotificationForAmount( _ units: Double , andTimeRemaining remaining: TimeInterval ? ) {
151- let notification = UILocalNotification ( )
162+ let notification = UNMutableNotificationContent ( )
152163
153- notification. alertTitle = NSLocalizedString ( " Pump Reservoir Low " , comment: " The notification title for a low pump reservoir " )
164+ notification. title = NSLocalizedString ( " Pump Reservoir Low " , comment: " The notification title for a low pump reservoir " )
154165
155166 let unitsString = NumberFormatter . localizedString ( from: NSNumber ( value: units) , number: . decimal)
156167
@@ -162,14 +173,20 @@ struct NotificationManager {
162173 intervalFormatter. includesTimeRemainingPhrase = true
163174
164175 if let remaining = remaining, let timeString = intervalFormatter. string ( from: remaining) {
165- notification. alertBody = String ( format: NSLocalizedString ( " %1$@ U left: %2$@ " , comment: " Low reservoir alert with time remaining format string. (1: Number of units remaining)(2: approximate time remaining) " ) , unitsString, timeString)
176+ notification. body = String ( format: NSLocalizedString ( " %1$@ U left: %2$@ " , comment: " Low reservoir alert with time remaining format string. (1: Number of units remaining)(2: approximate time remaining) " ) , unitsString, timeString)
166177 } else {
167- notification. alertBody = String ( format: NSLocalizedString ( " %1$@ U left " , comment: " Low reservoir alert format string. (1: Number of units remaining) " ) , unitsString)
178+ notification. body = String ( format: NSLocalizedString ( " %1$@ U left " , comment: " Low reservoir alert format string. (1: Number of units remaining) " ) , unitsString)
168179 }
169180
170- notification. soundName = UILocalNotificationDefaultSoundName
171- notification. category = Category . PumpReservoirLow. rawValue
181+ notification. sound = UNNotificationSound . default ( )
182+ notification. categoryIdentifier = Category . PumpReservoirLow. rawValue
172183
173- UIApplication . shared. presentLocalNotificationNow ( notification)
184+ let request = UNNotificationRequest (
185+ identifier: Category . PumpReservoirLow. rawValue,
186+ content: notification,
187+ trigger: nil
188+ )
189+
190+ UNUserNotificationCenter . current ( ) . add ( request)
174191 }
175192}
0 commit comments