tauri-plugin-notifications 0.4.5

A Tauri v2 plugin for sending notifications on desktop and mobile platforms with support for system notifications and push delivery via FCM and APNs.
Documentation
import Foundation
import UserNotifications

@objc public protocol NotificationHandlerProtocol {
  func willPresent(notification: UNNotification) -> UNNotificationPresentationOptions
  func didReceive(response: UNNotificationResponse)
}

@objc public class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
  public weak var notificationHandler: NotificationHandlerProtocol?

  override init() {
    super.init()
    let center = UNUserNotificationCenter.current()
    center.delegate = self
  }

  public func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
  ) {
    // Call willPresent for both local and push notifications
    let presentationOptions = notificationHandler?.willPresent(notification: notification)
    completionHandler(presentationOptions ?? [])
  }

  public func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
  ) {
    notificationHandler?.didReceive(response: response)

    completionHandler()
  }
}