-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppDelegate.swift
87 lines (75 loc) · 2.35 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// AppDelegate.swift
//
// Created by Juliya Smith on 5/9/17.
import UIKit
import UserNotifications
import PDKit
import PatchData
import WidgetKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var notifications: NotificationScheduling?
var sdk: PatchDataSDK?
var alerts: AlertProducing?
var tabs: TabReflective?
var nav: NavigationHandling?
var badge: PDBadgeReflective?
var widget: PDWidgetProtocol?
private var sessionInitialized = false
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
initDependencies()
#if DEBUG
// The `Notifications Test` is a test where the first hormone expires in a minute from now.
if PDCli.isNotificationsTest() {
badge?.clear()
if let sdk = sdk, let notifications = notifications {
if let hormone = sdk.hormones[0] {
notifications.requestExpiredHormoneNotification(for: hormone)
}
for pill in sdk.pills.all where pill.name == "Notification Test" {
notifications.requestDuePillNotification(pill)
}
}
PDCli.clearNotificationsFlag()
}
reflectBadges()
#endif
return true
}
func initDependencies() {
let sdk = PatchData()
self.sdk = sdk
self.nav = Navigation()
let badge = PDBadge(sdk: sdk)
self.badge = badge
self.notifications = Notifications(sdk: sdk, appBadge: badge)
self.widget = PDWidget()
reflectBadges()
WidgetCenter.shared.reloadAllTimelines()
}
static var isPad: Bool {
UIDevice.current.userInterfaceIdiom == .pad
}
static var current: AppDelegate? {
UIApplication.shared.delegate as? AppDelegate
}
func applicationWillEnterForeground(_ application: UIApplication) {
initDependencies()
reflectBadges()
}
func applicationWillTerminate(_ application: UIApplication) {
reflectBadges()
}
func applicationWillResignActive(_ application: UIApplication) {
reflectBadges()
}
private func reflectBadges() {
badge?.reflect()
tabs?.reflect()
}
}