Skip to content

Commit 2b6d4f4

Browse files
authored
Merge pull request #60 from loudnate/stop-notifications
Clear "Loop Not Running" notifications when the number of configured …
2 parents ef037ac + 67955bc commit 2b6d4f4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Loop/Managers/DeviceDataManager.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class DeviceDataManager: CarbStoreDelegate, TransmitterDelegate {
109109
rileyLinkManager.disconnectDevice(device)
110110

111111
AnalyticsManager.sharedManager.didChangeRileyLinkConnectionState()
112+
113+
if connectedPeripheralIDs.count == 0 {
114+
NotificationManager.clearLoopNotRunningNotifications()
115+
}
112116
}
113117

114118
// MARK: Pump data

Loop/Managers/NotificationManager.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ struct NotificationManager {
7474
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
7575
}
7676

77+
// Cancel any previous scheduled notifications in the Loop Not Running category
78+
static func clearLoopNotRunningNotifications() {
79+
let app = UIApplication.sharedApplication()
80+
81+
app.scheduledLocalNotifications?.filter({
82+
$0.category == Category.LoopNotRunning.rawValue
83+
}).forEach({
84+
app.cancelLocalNotification($0)
85+
})
86+
}
87+
7788
static func scheduleLoopNotRunningNotifications() {
7889
let app = UIApplication.sharedApplication()
7990

80-
// Cancel any previous scheduled notifications
81-
app.scheduledLocalNotifications?.filter({ $0.category == Category.LoopNotRunning.rawValue }).forEach({ app.cancelLocalNotification($0) })
91+
clearLoopNotRunningNotifications()
8292

8393
// Give a little extra time for a loop-in-progress to complete
8494
let gracePeriod = NSTimeInterval(minutes: 0.5)

0 commit comments

Comments
 (0)