forked from home-assistant/iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationService.swift
33 lines (29 loc) · 1.2 KB
/
NotificationService.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
import PromiseKit
import Shared
import UserNotifications
final class NotificationService: UNNotificationServiceExtension {
override func didReceive(
_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
Current.Log.info("didReceive \(request), user info \(request.content.userInfo)")
guard let server = Current.servers.server(for: request.content) else {
contentHandler(request.content)
return
}
firstly {
Current.notificationAttachmentManager.content(from: request.content, api: Current.api(for: server))
}.recover { error in
Current.Log.error("failed to get content, giving default: \(error)")
return .value(request.content)
}.done {
contentHandler($0)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content,
// otherwise the original push payload will be used.
Current.Log.warning("serviceExtensionTimeWillExpire")
}
}