iceriver102

onesignal

Dec 29th, 2019
325
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <RCTOneSignalExtensionService.h>
  2.  
  3. #import "NotificationService.h"
  4.  
  5. @interface NotificationService ()
  6.  
  7. @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
  8. @property (nonatomic, strong) UNNotificationRequest *receivedRequest;
  9. @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
  10.  
  11. @end
  12.  
  13. @implementation NotificationService
  14.  
  15. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  16.     self.receivedRequest = request;
  17.     self.contentHandler = contentHandler;
  18.     self.bestAttemptContent = [request.content mutableCopy];
  19.    
  20.     [RCTOneSignalExtensionService didReceiveNotificationRequest:self.receivedRequest withContent:self.bestAttemptContent];
  21.    
  22.     // DEBUGGING: Uncomment the 2 lines below and comment out the one above to ensure this extension is excuting
  23.     //            Note, this extension only runs when mutable-content is set
  24.     //            Setting an attachment or action buttons automatically adds this
  25.     // NSLog(@"Running NotificationServiceExtension");
  26.     // self.bestAttemptContent.body = [@"[Modified] " stringByAppendingString:self.bestAttemptContent.body];
  27.    
  28.     self.contentHandler(self.bestAttemptContent);
  29. }
  30.  
  31. - (void)serviceExtensionTimeWillExpire {
  32.     // Called just before the extension will be terminated by the system.
  33.     // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  34.    
  35.     [RCTOneSignalExtensionService serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  36.    
  37.     self.contentHandler(self.bestAttemptContent);
  38. }
  39.  
  40. @end
RAW Paste Data