FWNotificationManager


@interface FWNotificationManager : NSObject <UNUserNotificationCenterDelegate>

通知管理器

  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, class, readonly, strong) FWNotificationManager * _Nonnull sharedInstance
  • 异步查询通知权限状态,当前线程回调

    Declaration

    Objective-C

    - (void)authorizeStatus:
        (void (^_Nullable __strong)(enum FWAuthorizeStatus))completion;
  • 执行通知权限授权,主线程回调

    Declaration

    Objective-C

    - (void)requestAuthorize:
        (void (^_Nullable __strong)(enum FWAuthorizeStatus))completion;
  • 清空图标通知计数

    Declaration

    Objective-C

    - (void)clearNotificationBadges;
  • 设置远程推送处理句柄,参数为userInfo和原始通知对象

    Declaration

    Objective-C

    @property (nonatomic, copy) void (^_Nullable) (NSDictionary *_Nullable __strong, id _Nonnull __strong) remoteNotificationHandler;
  • 设置本地推送处理句柄,参数为userInfo和原始通知对象

    Declaration

    Objective-C

    @property (nonatomic, copy) void (^_Nullable) (NSDictionary *_Nullable __strong, id _Nonnull __strong) localNotificationHandler;
  • 注册通知处理器,iOS10+生效,iOS10以下详见UIApplicationDelegate

    Declaration

    Objective-C

    - (void)registerNotificationHandler;
  • 处理远程推送通知,支持NSDictionary|UNNotification|UNNotificationResponse

    Declaration

    Objective-C

    - (void)handleRemoteNotification:(id _Nonnull)notification;
  • 处理本地通知,支持NSDictionary|UNNotification|UNNotificationResponse

    Declaration

    Objective-C

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

    Declaration

    Objective-C

    - (void)registerLocalNotification:(NSString *_Nonnull)identifier
                                title:(NSString *_Nullable)title
                             subtitle:(NSString *_Nullable)subtitle
                                 body:(NSString *_Nullable)body
                             userInfo:(NSDictionary *_Nullable)userInfo
                                badge:(NSInteger)badge
                            soundName:(NSString *_Nullable)soundName
                         timeInterval:(NSTimeInterval)timeInterval
                              repeats:(BOOL)repeats
                                block:(void (^_Nullable __strong)(
                                          UNMutableNotificationContent
                                              *_Nonnull __strong))block;
  • 批量删除本地通知(未发出和已发出)

    Declaration

    Objective-C

    - (void)removeLocalNotification:(NSArray<NSString *> *_Nonnull)identifiers;
  • 删除所有本地通知(未发出和已发出)

    Declaration

    Objective-C

    - (void)removeAllLocalNotifications;
  • 前台收到推送

    Declaration

    Objective-C

    - (void)userNotificationCenter:(UNUserNotificationCenter *_Nonnull)center
           willPresentNotification:(UNNotification *_Nonnull)notification
             withCompletionHandler:
                 (void (^_Nonnull __strong)(UNNotificationPresentationOptions))
                     completionHandler;
  • 后台收到推送

    Declaration

    Objective-C

    - (void)userNotificationCenter:(UNUserNotificationCenter *_Nonnull)center
        didReceiveNotificationResponse:(UNNotificationResponse *_Nonnull)response
                 withCompletionHandler:
                     (void (^_Nonnull __strong)(void))completionHandler;
  • Undocumented

    Declaration

    Objective-C

    - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;