NotificationManager
@objc(FWNotificationManager)
@objcMembers
public class NotificationManager : NSObject, UNUserNotificationCenterDelegate
通知管理器
-
单例模式
Declaration
Swift
public static let sharedInstance: NotificationManager
-
异步查询通知权限状态,当前线程回调
Declaration
Swift
public func authorizeStatus(_ completion: ((AuthorizeStatus) -> Void)?)
-
执行通知权限授权,主线程回调
Declaration
Swift
public func requestAuthorize(_ completion: ((AuthorizeStatus) -> Void)?)
-
清空图标通知计数
Declaration
Swift
public func clearNotificationBadges()
-
设置远程推送处理句柄,参数为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)
-
registerLocalNotification(_:
title: subtitle: body: userInfo: badge: soundName: timeInterval: repeats: block: ) 注册本地通知,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()
-
前台收到推送
Declaration
Swift
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
-
后台收到推送
Declaration
Swift
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)