Advertisement
Guest User

NotificationService.m

a guest
Apr 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "OneSignal.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.     [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  21.    
  22.     self.contentHandler(self.bestAttemptContent);
  23. }
  24.  
  25. - (void)serviceExtensionTimeWillExpire {
  26.     // Called just before the extension will be terminated by the system.
  27.     // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  28.    
  29.     [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  30.    
  31.     self.contentHandler(self.bestAttemptContent);
  32. }
  33.  
  34. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement