cdts/xdts-ios 3/HoleNotification/NotificationService.m
2023-07-27 09:20:00 +08:00

52 lines
2.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// NotificationService.m
// HoleNotification
//
// Created by wujiangwei on 2022/5/26.
//
#import "NotificationService.h"
#import <GTExtensionSDK/GeTuiExtSdk.h>
@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