Configuring Extensions with Smartech SDK
Configuring Service Extension
You need to add the following changes in the Notification Service Extension's NotificationService class.
Method 1 :
//In NotificationService.h
#import <UserNotifications/UserNotifications.h>
#import <NetCorePush/NetCorePush.h>
@interface NotificationService : SMTNotificationServiceExtension
@end
//In NotificationService.m
#import "NotificationService.h"
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
[super didReceiveNotificationRequest:request withContentHandler:contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
[super serviceExtensionTimeWillExpire];
}
@end
import UserNotifications
import NetCorePush
class NotificationService: SMTNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
super.didReceive(request, withContentHandler: contentHandler);
}
override func serviceExtensionTimeWillExpire() {
super.serviceExtensionTimeWillExpire()
}
}
Method 2 :
//In NotificationService.h
#import <UserNotifications/UserNotifications.h>
@interface NotificationService : UNNotificationServiceExtension
@end
//In NotificationService.m
#import "NotificationService.h"
#import <Smartech/Smartech.h>
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
NSDictionary *userInfo = request.content.userInfo;
if ([[Smartech sharedInstance] isNotificationFromSmartech:userInfo]) {
[[Smartech sharedInstance] didReceiveNotificationRequest:request withContentHandler:contentHandler];
} else {
//Perform other actions
}
}
- (void)serviceExtensionTimeWillExpire {
[[Smartech sharedInstance] serviceExtensionTimeWillExpire];
}
@end
import UserNotifications
import NetCorePush
class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let userInfo = request.content.userInfo
if Smartech.sharedInstance().isNotification(fromSmartech: userInfo) {
Smartech.sharedInstance().didReceive(request, withContentHandler: contentHandler)
} else {
}
}
override func serviceExtensionTimeWillExpire() {
Smartech.sharedInstance().serviceExtensionTimeWillExpire()
}
}
#ProTip
It is recommended to use Method 1.
Configuring Content Extension
For Objective-C Project replace the following files from the file provided in Rich Files\ObjC Folder:
- MainInterface.storyboard
- NotificationViewController.h
- NotificationViewController.m
For Swift Project replace the following files from the file provided in Rich Files\Swift Folder:
- MainInterface.storyboard
- NotificationViewController.swift
In your Content Extensions Info.plist under NSExtension -> NSExtensionAttributes
- Replace the
UNNotificationExtensionCategory
value with String valuesmartechPushCategory
- Add the UNNotificationExtensionDefaultContentHidden key with Boolean value NO.
Updated over 4 years ago