42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Objective-C
		
	
//
 | 
						|
//  NotificationService.m
 | 
						|
//  OneSignalNotificationServiceExtension
 | 
						|
//
 | 
						|
//  Created by Bun LV on 07/09/2022.
 | 
						|
//
 | 
						|
 | 
						|
#import <OneSignal/OneSignal.h>
 | 
						|
 | 
						|
#import "NotificationService.h"
 | 
						|
 | 
						|
@interface NotificationService ()
 | 
						|
 | 
						|
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
 | 
						|
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
 | 
						|
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
 | 
						|
 | 
						|
@end
 | 
						|
 | 
						|
@implementation NotificationService
 | 
						|
 | 
						|
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
 | 
						|
    
 | 
						|
    self.receivedRequest = request;
 | 
						|
    self.contentHandler = contentHandler;
 | 
						|
    self.bestAttemptContent = [request.content mutableCopy];
 | 
						|
    
 | 
						|
    [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest
 | 
						|
                           withMutableNotificationContent:self.bestAttemptContent
 | 
						|
                                       withContentHandler:self.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.
 | 
						|
    [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
 | 
						|
        
 | 
						|
    self.contentHandler(self.bestAttemptContent);
 | 
						|
}
 | 
						|
 | 
						|
@end
 |