NotificationService.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // NotificationService.m
  3. // RADriversNotificationService
  4. //
  5. // Created by Jack on 2018/7/13.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "NotificationService.h"
  9. @interface NotificationService ()
  10. @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
  11. @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
  12. @end
  13. @implementation NotificationService
  14. - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  15. self.contentHandler = contentHandler;
  16. self.bestAttemptContent = [request.content mutableCopy];
  17. // Modify the notification content here...
  18. // self.bestAttemptContent.title = @"GoGoGo";
  19. // NSDictionary *userInfo = self.bestAttemptContent.userInfo;
  20. // NSLog(@"receive notification userInfo: %@",userInfo);
  21. self.bestAttemptContent.userInfo = @{
  22. @"alert" : @"",
  23. @"content-available" : @1,
  24. @"report-location" : @1
  25. };
  26. self.contentHandler(self.bestAttemptContent);
  27. }
  28. - (void)serviceExtensionTimeWillExpire {
  29. // Called just before the extension will be terminated by the system.
  30. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  31. self.contentHandler(self.bestAttemptContent);
  32. }
  33. @end