NotificationService.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // NotificationService.m
  3. // NotificationService
  4. //
  5. // Created by gtjx-z on 2025/4/10.
  6. //
  7. #import "NotificationService.h"
  8. @interface NotificationService ()
  9. @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
  10. @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
  11. @end
  12. @implementation NotificationService
  13. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  14. self.contentHandler = contentHandler;
  15. self.bestAttemptContent = [request.content mutableCopy];
  16. // Modify the notification content here...
  17. self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
  18. self.contentHandler(self.bestAttemptContent);
  19. }
  20. - (void)serviceExtensionTimeWillExpire {
  21. // Called just before the extension will be terminated by the system.
  22. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  23. self.contentHandler(self.bestAttemptContent);
  24. }
  25. @end