cdts/xdts-ios 3/HoleNotification/NotificationService.m

52 lines
2.1 KiB
Mathematica
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
//
// 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