NotificationService.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // NotificationService.m
  3. // NotificationService
  4. //
  5. // Created by 张嵘 on 2021/9/23.
  6. //
  7. #import "NotificationService.h"
  8. #import <GTExtensionSDK/GeTuiExtSdk.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 = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
  19. //
  20. // self.contentHandler(self.bestAttemptContent);
  21. NSLog(@"----将APNs信息交由个推处理----");
  22. [GeTuiExtSdk handelNotificationServiceRequest:request withAttachmentsComplete:^(NSArray *attachments, NSArray* errors) {
  23. //注意:是否修改下发后的title内容以项目实际需求而定
  24. //self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [需求而定]", self.bestAttemptContent.title];
  25. self.bestAttemptContent.attachments = attachments; //设置通知中的多媒体附件
  26. NSLog(@"个推处理APNs消息遇到错误:%@",errors); //如果APNs处理有错误,可以在这里查看相关错误详情
  27. self.contentHandler(self.bestAttemptContent); //展示推送的回调处理需要放到个推回执完成的回调中
  28. }];
  29. }
  30. - (void)serviceExtensionTimeWillExpire {
  31. // Called just before the extension will be terminated by the system.
  32. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
  33. //销毁SDK,释放资源
  34. [GeTuiExtSdk destory];
  35. //结束 NotificationService 调用
  36. self.contentHandler(self.bestAttemptContent);
  37. }
  38. @end