NotificationService.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // NotificationService.m
  3. // NotificationServiceExtension
  4. //
  5. // Created by iOS on 2023/4/22.
  6. //
  7. #import "NotificationService.h"
  8. #import <UIKit/UIKit.h>
  9. #import <OneSignal/OneSignal.h>
  10. @interface NotificationService ()
  11. @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
  12. @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
  13. @property (nonatomic, strong) UNNotificationRequest *receivedRequest;
  14. @end
  15. @implementation NotificationService
  16. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  17. self.receivedRequest = request;
  18. self.contentHandler = contentHandler;
  19. self.bestAttemptContent = [request.content mutableCopy];
  20. [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest
  21. withMutableNotificationContent:self.bestAttemptContent
  22. withContentHandler:self.contentHandler];
  23. }
  24. - (void)serviceExtensionTimeWillExpire {
  25. NSLog(@"------serviceExtensionTimeWillExpire-------");
  26. [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  27. self.contentHandler(self.bestAttemptContent);
  28. }
  29. @end