NotificationManager

@objc(FWNotificationManager)
@objcMembers
public class NotificationManager : NSObject, UNUserNotificationCenterDelegate

通知管理器

Accessor

  • 单例模式

    Declaration

    Swift

    public static let sharedInstance: NotificationManager

Authorize

Badge

Handler

  • 设置远程推送处理句柄,参数为userInfo和原始通知对象

    Declaration

    Swift

    public var remoteNotificationHandler: (([AnyHashable : Any]?, Any) -> Void)?
  • 设置本地推送处理句柄,参数为userInfo和原始通知对象

    Declaration

    Swift

    public var localNotificationHandler: (([AnyHashable : Any]?, Any) -> Void)?
  • 注册通知处理器,iOS10+生效,iOS10以下详见UIApplicationDelegate

    Declaration

    Swift

    public func registerNotificationHandler()
  • 处理远程推送通知,支持NSDictionary|UNNotification|UNNotificationResponse

    Declaration

    Swift

    public func handleRemoteNotification(_ notification: Any)
  • 处理本地通知,支持NSDictionary|UNNotification|UNNotificationResponse

    Declaration

    Swift

    public func handleLocalNotification(_ notification: Any)

Local

  • 注册本地通知,badge为0时不改变,soundName为default时为默认声音,timeInterval为触发时间间隔(0为立即触发),block为自定义内容句柄,iOS15+支持时效性通知,需entitlements配置开启

    Declaration

    Swift

    public func registerLocalNotification(_ identifier: String, title: String?, subtitle: String?, body: String?, userInfo: [AnyHashable : Any]?, badge: Int, soundName: String?, timeInterval: TimeInterval, repeats: Bool, block: ((UNMutableNotificationContent) -> Void)?)
  • 批量删除本地通知(未发出和已发出)

    Declaration

    Swift

    public func removeLocalNotification(_ identifiers: [String])
  • 删除所有本地通知(未发出和已发出)

    Declaration

    Swift

    public func removeAllLocalNotifications()

UNUserNotificationCenterDelegate