These docs are for v1.0. Click to read the latest docs for v2.0.

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:

  1. MainInterface.storyboard
  2. NotificationViewController.h
  3. NotificationViewController.m

For Swift Project replace the following files from the file provided in Rich Files\Swift Folder:

  1. MainInterface.storyboard
  2. NotificationViewController.swift

In your Content Extensions Info.plist under NSExtension -> NSExtensionAttributes

  1. Replace the UNNotificationExtensionCategory value with String value smartechPushCategory
  2. Add the UNNotificationExtensionDefaultContentHidden key with Boolean value NO.