The Notification Service Extension modifies the notification content by adding actions, push polls and allows you to take advantage of iOS 10+ notification features.
1. Add new target to your project (File->New->Target
) and create Notification Service Extension, and name it PushbotsNSExtension
, Press cancel on the "Activate PushbotsNSExtension
scheme" prompt:
Make sure deployment target of the Notification Extesion Service is set to 10 or higher under General tab.
2. Open NotificationService.m
or NotificationService.swift
under PushbotsNSExtension Group
and copy the code below:
Objective-C NotificationService.m
// NotificationService.m
#import <Pushbots/Pushbots.h>
#import "NotificationService.h"
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) UNNotificationRequest *notificationRequest;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.notificationRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
[Pushbots didReceiveNotificationExtensionRequest:self.notificationRequest withContent:self.bestAttemptContent];
self.contentHandler(self.bestAttemptContent);
}
- (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.
[Pushbots serviceExtensionTimeWillExpireRequest:self.notificationRequest withContent:self.bestAttemptContent];
self.contentHandler(self.bestAttemptContent);
}
@end
3. Click on PushbotsNSExtension
Target, select "Build Settings" and search for Code Signing Entitlements
. make sure that Debug and Release are empty.
4. Click on Build Phases
, scroll too link Binary with libraries
then click on add button.
5.choose Add other
, then Add files
, then choose this Path:platforms/ios/<project_name>/Plugins/pushbots-crodova-plugin/Pushbots.framework
6. Click on Add again and add:SystemConfiguration.framework
CoreTelephony.framework
7. Build and run the app.