| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // NotificationService.m
- // RADriversNotificationService
- //
- // Created by Jack on 2018/7/13.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "NotificationService.h"
- @interface NotificationService ()
- @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
- @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
- @end
- @implementation NotificationService
- - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
- self.contentHandler = contentHandler;
- self.bestAttemptContent = [request.content mutableCopy];
-
- // Modify the notification content here...
- // self.bestAttemptContent.title = @"GoGoGo";
-
-
- // NSDictionary *userInfo = self.bestAttemptContent.userInfo;
- // NSLog(@"receive notification userInfo: %@",userInfo);
- //
- // self.bestAttemptContent.userInfo = @{
- // @"alert" : @"",
- // @"content-available" : @1,
- // @"report-location" : @1
- // };
-
- NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.radrivers"];
- NSString *obj = [userDefaults objectForKey:@"test"];
- NSLog(@"obj: %@",obj);
- self.bestAttemptContent.title = obj;
-
- self.contentHandler(self.bestAttemptContent);
- }
- - (void)serviceExtensionTimeWillExpire {
- // Called just before the extension will be terminated by the system.
- // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
- self.contentHandler(self.bestAttemptContent);
- }
- @end
|