NotificationService.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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) void (^contentHandler)(UNNotificationContent *contentToDeliver);
  14. @property (nonatomic, strong) UNNotificationRequest *receivedRequest;
  15. //@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
  16. @end
  17. @implementation NotificationService
  18. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  19. self.receivedRequest = request;
  20. self.contentHandler = contentHandler;
  21. self.bestAttemptContent = [request.content mutableCopy];
  22. [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest
  23. withMutableNotificationContent:self.bestAttemptContent
  24. withContentHandler:self.contentHandler];
  25. }
  26. - (void)serviceExtensionTimeWillExpire {
  27. NSLog(@"------serviceExtensionTimeWillExpire-------");
  28. [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  29. self.contentHandler(self.bestAttemptContent);
  30. }
  31. @end