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

Adding And Configuring of Extensions in your App

Adding Service Extension

Notification Service Extension is used to display media notifications like Image, Video, Audio, and Gif sent from Smartech.

  1. In your Xcode go to menu File > New > Target > Select Notification Service Extension.
  2. Click the Next button and fill in the Product Name, here in the example we are using SmartechNSE.
  3. Click the Finish button.
  4. Set the deployment target to a minimum of 10.0.
  5. You need to create a different Bundle Identifier and provision profile for this extension. For example ‘com.CompanyName.ProductName.ProductNameServiceExtension’

Adding Content Extension

Notification Content Extension is used only to display carousel notification sent from Smartech.

  1. In your Xcode go to menu File > New > Target > Select Notification Content Extension.
  2. Click the Next button and fill in the Product Name, here in the example we are using SmartechNCE.
  3. Click the Finish button
  4. Set the deployment target to a minimum of 10.0.
  5. You need to create a different Bundle Identifier and provision profile for this extension. For example ‘com.CompanyName.ProductName.ProductNameContentExtension’

Enabling Capabilities for Service and Content Extension

📘

Note:

  1. Make sure you add App Transport Security Settings with Allow Arbitrary Loads as YES in Info.plist of App, Service Extension and Content Extension to support Http calls.
  2. App Groups must be same between App, Service Extension, and Content Extension.

For Smartech SDK to work in your project you need to enable below app capabilities in your main app.

  1. App Groups - Enable/Add and select a valid App Group for your app. This is used by App, Service Extension and Content Extension to access data as all three are different targets

You can refer to the below PDF for detailed steps to enable app capabilities in your main app and extensions, refer here

Configuring Service Extensions Info.plist

You need to add a key named SmartechKeys with type Dictionary. Init add the following keys and values with its types.

KeyData typeDescription
SmartechAppGroupStringThe app group that is selected in capabilities section. It is used to share data between App and Extensions.
SmartechAppIdStringThe app id received from Smartech panel under assets section.

Following is the source code snippet of service extensions Info.plist for key SmartechKeys:

<key>SmartechKeys</key>
    <dict>
        <key>SmartechAppGroup</key>
        <string>group.com.CompanyName.ProductName</string>
        <key>SmartechAppId</key>
        <string>abcdef123456abcdef123456abcd1234</string>
    </dict>

Following is the image representation of service extensions Info.plist for key SmartechKeys:

714

Configuring Content Extensions Info.plist

You need to add a key named SmartechKeys with type Dictionary. Init add the following key and value with its type.

KeyData typeDescription
SmartechAppGroupStringThe app group that is selected in capabilities section. It is used to share data between App and Extensions.

Following is the source code snippet of content extensions Info.plist for key SmartechKeys:

<key>SmartechKeys</key>
	<dict>
		<key>SmartechAppGroup</key>
		<string>group.com.CompanyName.ProductName</string>
	</dict>

Following is the image representation of content extensions Info.plist for key SmartechKeys:

673

Changes in Podfile

If you are using the framework from cocoapods then you need to update it with the following lines in Podfile.

#service extension target
target 'YourServiceExtensionTarget' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!
  # Pods for 'YourServiceExtensionTarget'
pod 'Smartech-iOS-SDK'
end
 
#content extension target
target 'YourContentExtensionTarget' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!
  # Pods for 'YourContentExtensionTarget'
pod 'Smartech-iOS-SDK'
end

Below is the final output of your Podfile.

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
 
#app target
target 'YourAppTarget' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!
  # Pods for YourAppTarget
pod 'Smartech-iOS-SDK'
end

#service extension target
target 'YourServiceExtensionTarget' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!
  # Pods for 'YourServiceExtensionTarget'
pod 'Smartech-iOS-SDK'
end
 
#content extension target
target 'YourContentExtensionTarget' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!
  # Pods for 'YourContentExtensionTarget'
pod 'Smartech-iOS-SDK'
end

These updated lines in your Podfile will install the Smartech SDK for both the extensions. Save this file and install the dependencies which are added for extensions with pod install command via terminal.

pod install

Configuring Service Extension with Smartech SDK

You need to perform the following changes in the Notification Service Extension's NotificationService class.

Method 1 : Inherit SMTNotificationServiceExtension in NotificationService class

//In NotificationService.h

#import <UserNotifications/UserNotifications.h>
#import <Smartech/Smartech.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 Smartech

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 : Create an object of SMTNotificationServiceExtension and call the methods

//In NotificationService.h

#import <UserNotifications/UserNotifications.h>

@interface NotificationService : UNNotificationServiceExtension

@end

 
//In NotificationService.m

#import "NotificationService.h"
#import <Smartech/Smartech.h>

@implementation NotificationService

SMTNotificationServiceExtension *smartechServiceExtension;

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  //...
  if ([[Smartech sharedInstance] isNotificationFromSmartech:(nonnull NSDictionary *)) {
    smartechServiceExtension = [[SMTNotificationServiceExtension alloc] init];
    [smartechServiceExtension didReceiveNotificationRequest:request withContentHandler:contentHandler];
  }
  //...
}

- (void)serviceExtensionTimeWillExpire {
  //...
  [smartechServiceExtension serviceExtensionTimeWillExpire];
  //...
}

@end
import UserNotifications
import Smartech

class NotificationService: UNNotificationServiceExtension {
  
  let smartechServiceExtension = SMTNotificationServiceExtension()
  
  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    //...
    if Smartech.sharedInstance().isNotification(fromSmartech: [AnyHashable : Any]) {
      smartechServiceExtension.didReceive(request, withContentHandler: contentHandler)
    }
    //...
  }
  
  override func serviceExtensionTimeWillExpire() {
    //...
    smartechServiceExtension.serviceExtensionTimeWillExpire()
    //...
  }
}

📘

#ProTip

It is recommended to use Method 1 if you are using only Smartech SDK for the rich notifications.

Configuring Content Extension with Smartech SDK

Replace the following code in your NotificationViewController class

//This is NotificationViewController.m file

#import "NotificationViewController.h"
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
#import <Smartech/Smartech.h>

@interface NotificationViewController () <UNNotificationContentExtension>

@property (weak, nonatomic) IBOutlet UIView *customView;

@end

@implementation NotificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[Smartech sharedInstance] loadCustomNotificationContentView:self.customView];
}

- (void)didReceiveNotification:(UNNotification *)notification {
    [[Smartech sharedInstance] didReceiveCustomNotification:notification];
}

- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption option))completion {
    
    [[Smartech sharedInstance] didReceiveCustomNotificationResponse:response completionHandler:^(UNNotificationContentExtensionResponseOption option) {
        completion(option);
    }];
    
}

@end
import UIKit
import UserNotifications
import UserNotificationsUI
import Smartech

class NotificationViewController: UIViewController, UNNotificationContentExtension {
    
    @IBOutlet var customBgView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        Smartech.sharedInstance().loadCustomNotificationContentView(customBgView)
        // Do any required interface initialization here.
    }
    
    func didReceive(_ notification: UNNotification) {
        Smartech.sharedInstance().didReceiveCustomNotification(notification)
    }
    
    func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
        Smartech.sharedInstance().didReceiveCustomNotificationResponse(response) { (option) in
            completion(option)
        }
    }
}

For storyboard changes in your Content Extension, you need to check this PDF.

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

  1. Change the UNNotificationExtensionCategory datatype with Array in which it will be consisted of 3 values :
    a. Item 0 will be of type String with value SmartechCarouselLandscapeNotification
    b. Item 1 will be of type String with value SmartechCarouselPortraitNotification
    c. Item 2 will be of type String with value SmartechCarouselFallbackNotification.
  2. Add the UNNotificationExtensionDefaultContentHidden key with Boolean value NO.