2024-05-29 15:14:12 +08:00

29 lines
1.1 KiB
Swift

//
// LevelProcessor.swift
// NotificationServiceExtension
//
// Created by huangfeng on 2024/5/29.
// Copyright © 2024 Fin. All rights reserved.
//
import Foundation
///
class LevelProcessor: NotificationContentProcessor {
func process(content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
if #available(iOSApplicationExtension 15.0, *) {
if let level = bestAttemptContent.userInfo["level"] as? String {
let interruptionLevels: [String: UNNotificationInterruptionLevel] = [
"passive": UNNotificationInterruptionLevel.passive,
"active": UNNotificationInterruptionLevel.active,
"timeSensitive": UNNotificationInterruptionLevel.timeSensitive,
"timesensitive": UNNotificationInterruptionLevel.timeSensitive,
"critical": UNNotificationInterruptionLevel.critical
]
bestAttemptContent.interruptionLevel = interruptionLevels[level] ?? .active
}
}
return bestAttemptContent
}
}