When integrating an external push provider along with Insider, you might duplicate the NotificationService extension. You can create a separate NotificationService extension to handle push notifications.
If you have two NotificationService extensions, they may conflict inside the application. Instead, use a single NotificationService extension and handle received push notifications based on their source. The example below handles the NotificationService for both Insider One 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