Jon Mårtensson 4 anni fa
parent
commit
b39f71572c

+ 19 - 0
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -102,6 +102,25 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
                 return
             }
 
+            let content = UNMutableNotificationContent()
+            content.badge = 0
+            let lastGlucose: BloodGlucose? = self.glucoseStorage.recent().last
+            if lastGlucose != nil {
+                if date.timeIntervalSince(lastGlucose!.dateString) < 5.1 * 60 {
+                    content.badge = NSNumber(value: lastGlucose!.glucose ?? 0)
+                }
+            }
+
+            let request = UNNotificationRequest(
+                identifier: "badgeGlucose",
+                content: content,
+                trigger: nil
+            )
+
+            DispatchQueue.main.async {
+                UNUserNotificationCenter.current().add(request)
+            }
+
             var updateInterval: TimeInterval = 1.5 * 60
 
             switch date.timeIntervalSince(lastHeartBeatTime) {

+ 17 - 0
FreeAPS/Sources/Application/FreeAPSApp.swift

@@ -61,3 +61,20 @@ private extension Swinject.Resolver {
         }
     }
 }
+
+class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
+    func userNotificationCenter(
+        _: UNUserNotificationCenter,
+        willPresent _: UNNotification,
+        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
+            -> Void
+    ) {
+        completionHandler([.banner, .badge, .sound])
+    }
+
+    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
+        // Override point for customization after application launch.
+        UNUserNotificationCenter.current().delegate = self
+        return true
+    }
+}