NotificationService.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //
  22. // self.bestAttemptContent.userInfo = @{
  23. // @"alert" : @"",
  24. // @"content-available" : @1,
  25. // @"report-location" : @1
  26. // };
  27. NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.radrivers"];
  28. NSString *obj = [userDefaults objectForKey:@"test"];
  29. NSLog(@"obj: %@",obj);
  30. self.bestAttemptContent.title = obj;
  31. self.contentHandler(self.bestAttemptContent);
  32. }
  33. - (void)serviceExtensionTimeWillExpire {
  34. // Called just before the extension will be terminated by the system.
  35. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  36. self.contentHandler(self.bestAttemptContent);
  37. }
  38. @end