// // NotificationService.m // HoleNotification // // Created by wujiangwei on 2022/5/26. // #import "NotificationService.h" #import @interface NotificationService () @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; @end @implementation NotificationService ///APNs 推送的消息送达时会调用这个方法,此时你可以对推送的内容进行处理 - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; // NSLog(@"----将APNs信息交由个推处理----"); ///APNS统计及多媒体推送消息处理 [GeTuiExtSdk handelNotificationServiceRequest:request withAttachmentsComplete:^(NSArray *attachments, NSArray* errors) { //注意:是否修改下发后的title内容以项目实际需求而定 //self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [需求而定]", self.bestAttemptContent.title]; //设置通知中的多媒体附件 self.bestAttemptContent.attachments = attachments; //如果APNs处理有错误,可以在这里查看相关错误详情 NSLog(@"个推处理APNs消息遇到错误:%@",errors); //展示推送的回调处理需要放到个推回执完成的回调中 self.contentHandler(self.bestAttemptContent); }]; } ///如果didReceiveNotificationRequest方法在限定时间内没有调用 contentHandler方法结束处理,则会在过期之前进行回调本方法进行紧急处理 - (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. //销毁SDK,释放资源 [GeTuiExtSdk destory]; //结束 NotificationService 调用 self.contentHandler(self.bestAttemptContent); } @end