iOS/Sources/Extensions/NotificationService/NotificationService.swift
Zac West 640cca884b
Add SwiftFormat to project (#1463)
Adds new fastlane lanes:
- `fastlane lint` which checks the linters
- `fastlane autocorrect` which applies the linters which can autocorrect (Rubocop, SwiftFormat)

Adds a build step to the Codegen abstract target which runs SwiftFormat in lint mode, pointing out what it's going to change when run.

Applies SwiftFormat to nearly all code -- exempts a few externally-sourced files and generated code.
2021-02-05 22:06:25 -08:00

29 lines
1.1 KiB
Swift

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)")
Current.api.then(on: nil) { api in
NotificationAttachmentManager().content(from: request.content, api: api)
}.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")
}
}