LevelProcessor.swift 1.1 KB

12345678910111213141516171819202122232425262728
  1. //
  2. // LevelProcessor.swift
  3. // NotificationServiceExtension
  4. //
  5. // Created by huangfeng on 2024/5/29.
  6. // Copyright © 2024 Fin. All rights reserved.
  7. //
  8. import Foundation
  9. /// 通知中断级别
  10. class LevelProcessor: NotificationContentProcessor {
  11. func process(identifier: String, content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
  12. if #available(iOSApplicationExtension 15.0, *) {
  13. if let level = bestAttemptContent.userInfo["level"] as? String {
  14. let interruptionLevels: [String: UNNotificationInterruptionLevel] = [
  15. "passive": UNNotificationInterruptionLevel.passive,
  16. "active": UNNotificationInterruptionLevel.active,
  17. "timeSensitive": UNNotificationInterruptionLevel.timeSensitive,
  18. "timesensitive": UNNotificationInterruptionLevel.timeSensitive,
  19. "critical": UNNotificationInterruptionLevel.critical
  20. ]
  21. bestAttemptContent.interruptionLevel = interruptionLevels[level] ?? .active
  22. }
  23. }
  24. return bestAttemptContent
  25. }
  26. }