forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
106 lines (75 loc) · 3.75 KB
/
AppDelegate.swift
File metadata and controls
106 lines (75 loc) · 3.75 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// AppDelegate.swift
// Naterade
//
// Created by Nathan Racklyeft on 8/15/15.
// Copyright © 2015 Nathan Racklyeft. All rights reserved.
//
import UIKit
import LoopKit
final class AppDelegate: UIResponder, UIApplicationDelegate, WindowProvider {
var window: UIWindow?
private let loopAppManager = LoopAppManager()
private let log = DiagnosticLog(category: "AppDelegate")
// MARK: - UIApplicationDelegate - Initialization
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
log.default("%{public}@ with launchOptions: %{public}@", #function, String(describing: launchOptions))
setenv("CFNETWORK_DIAGNOSTICS", "3", 1)
log.default("lastPathComponent = %{public}@", String(describing: Bundle.main.appStoreReceiptURL?.lastPathComponent))
loopAppManager.initialize(windowProvider: self, launchOptions: launchOptions)
loopAppManager.launch()
return loopAppManager.isLaunchComplete
}
// MARK: - UIApplicationDelegate - Life Cycle
func applicationDidBecomeActive(_ application: UIApplication) {
log.default(#function)
loopAppManager.didBecomeActive()
}
func applicationWillResignActive(_ application: UIApplication) {
log.default(#function)
}
func applicationDidEnterBackground(_ application: UIApplication) {
log.default(#function)
}
func applicationWillEnterForeground(_ application: UIApplication) {
log.default(#function)
loopAppManager.askUserToConfirmLoopReset()
}
func applicationWillTerminate(_ application: UIApplication) {
log.default(#function)
}
// MARK: - UIApplicationDelegate - Environment
func applicationProtectedDataDidBecomeAvailable(_ application: UIApplication) {
DispatchQueue.main.async {
if self.loopAppManager.isLaunchPending {
self.loopAppManager.launch()
}
}
}
// MARK: - UIApplicationDelegate - Remote Notification
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
log.default(#function)
loopAppManager.remoteNotificationRegistrationDidFinish(.success(deviceToken))
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
log.error("%{public}@ with error: %{public}@", #function, String(describing: error))
loopAppManager.remoteNotificationRegistrationDidFinish(.failure(error))
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
log.default(#function)
completionHandler(loopAppManager.handleRemoteNotification(userInfo as? [String: AnyObject]) ? .noData : .failed)
}
// MARK: - UIApplicationDelegate - Deeplinking
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
loopAppManager.handle(url)
}
// MARK: - UIApplicationDelegate - Continuity
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
log.default(#function)
return loopAppManager.userActivity(userActivity, restorationHandler: restorationHandler)
}
// MARK: - UIApplicationDelegate - Interface
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return loopAppManager.supportedInterfaceOrientations
}
}