-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathAppDelegate.swift
98 lines (80 loc) · 3.04 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
88
89
90
91
92
93
94
95
96
97
98
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var isUnitTesting: Bool {
ProcessInfo.processInfo.arguments.contains("-UNITTEST")
}
func application(
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
guard !isUnitTesting else { return true }
let rootWindow = NovaWindow()
window = rootWindow
// the requirement is to set the delegate before living didFinishLaunching
setupPushNotificationsDelegate()
let presenter = RootPresenterFactory.createPresenter(with: rootWindow)
presenter.loadOnLaunch()
rootWindow.makeKeyAndVisible()
return true
}
func setupPushNotificationsDelegate() {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.delegate = self
}
func application(
_: UIApplication,
open url: URL,
options _: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
URLHandlingService.shared.handle(url: url)
}
func application(_: UIApplication, supportedInterfaceOrientationsFor _: UIWindow?) -> UIInterfaceOrientationMask {
DeviceOrientationManager.shared.enabledOrientations
}
func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Logger.shared.debug("Did receive APNS push token")
PushNotificationsServiceFacade.shared.updateAPNS(token: deviceToken)
}
func application(_: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Logger.shared.error("Failed to register push notifications: \(error)")
}
func application(
_: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler _: @escaping ([any UIUserActivityRestoring]?) -> Void
) -> Bool {
guard
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL
else {
return false
}
URLHandlingService.shared.handle(url: url)
return true
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_: UNUserNotificationCenter,
willPresent _: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
if #available(iOS 14.0, *) {
completionHandler([.banner, .list, .badge, .sound])
} else {
completionHandler([.alert, .badge, .sound])
}
}
func userNotificationCenter(
_: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
let userInfo = response.notification.request.content.userInfo
PushNotificationHandlingService.shared.handle(userInfo: userInfo) { _ in
completionHandler()
}
}
}