When integrating an external push provider along with Insider, you might duplicate the NotificationService extension. You can create a separate NotificationService extension for handling the push notifications.
If you have two NotificationService extensions, they may conflict inside the application. Instead, you should use one NotificationService extension and handle the received push notifications according to their sources. The example below handles the NotificationService for both Insider and external push providers.
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) NSString *source;
@end
// DO NOT FORGET to change this to your app group
static NSString *APP_GROUP = @"group.com.useinsider.iGurmeV3";
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.receivedRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
NSDictionary *notificationData = request.content.userInfo;
self.source = [notificationData objectForKey:@"source"];
// YOU CAN CUSTOMIZE THESE
NSString *nextButtonText = @">>";
NSString *goToAppText = @"Launch App";
if ([self.source isEqual: @"Insider"]) {
[InsiderPushNotification showInsiderRichPush:request appGroup:APP_GROUP nextButtonText:nextButtonText goToAppText:goToAppText success:^(UNNotificationAttachment *attachment) {
self->_bestAttemptContent.attachments = [self->_bestAttemptContent.attachments arrayByAddingObject:attachment];
self.contentHandler(self.bestAttemptContent);
}];
return;
}
//one signal
[OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
self.contentHandler(self.bestAttemptContent);
}
- (void)serviceExtensionTimeWillExpire {
if ([self.source isEqual: @"Insider"]) {
self.contentHandler(self.bestAttemptContent);
return;
}
// one signal
[OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
self.contentHandler(self.bestAttemptContent);
}
@end