Configure the Content Extension for the iOS Extension SDK

To show rich media notifications in your app, add and configure a content extension in your project.

The configuration steps vary depending on your programming language. If you use Swift, click View Swift code example to expand the Swift example. If you use Objective-C, click View Objective-C code example to expand the Objective-C example.

Note

Add a Content Extension Target 

Notification Content Extensions run as separate processes within your app, providing isolation and enhancing security.

  1. In Xcode, go to File > New > Target.
  2. From the iOS > Application Extension section, select Notification Content Extension.
  3. Click Next.
  4. Provide a name and configure your extension settings.
  5. Click Finish.
  6. In the general settings for your target, verify that the Frameworks, Libraries, and Embedded Content section lists the new extension. If it isn’t present, add it.

Integrate the Extension SDK with Your Content Extension 

Integrate the MCExtensionSDK into your Content Extension by using the same process as the Service Extension. For detailed instructions, see Integrate the Extension SDK with the Service Extension.

After you complete the integration, verify that your Content Extension’s target settings list the library in the Frameworks, Libraries, and Embedded Content section.

The Frameworks, Libraries, and Embedded Content section for a project, showing the new extension highlighted.

Inherit from SFMCNotificationViewController 

Remove the provided sample code and inherit the main class of the Content Extension from SFMCNotificationViewController.

View Swift code example
1import UIKit
2import UserNotifications
3import UserNotificationsUI
4import MCExtensionSDK
5
6class NotificationViewController: SFMCNotificationViewController { }
View Objective-C code example

Header file

1#import <UIKit/UIKit.h>
2#import <MCExtensionSDK/MCExtensionSDK.h>
3
4@interface NotificationViewController : SFMCNotificationViewController
5
6@end

Implementation file

1#import "NotificationViewController.h"
2
3@implementation NotificationViewController
4
5@end

SFMCNotificationViewController fully manages UI rendering. Don’t implement or override any UIViewController methods in the principal class of the content extension.

Note

Project and Info.plist Configuration 

Configure your project and content extension’s Info.plist file to register the notification category, build the UI programmatically, and turn on user interaction.

Set Up the Extension Category 

Set up the notification category in your content extension’s Info.plist file to match the category in Marketing Cloud Next.

  1. Work with your Marketing Admin to obtain the category name for your Rich UI template.
  2. In your content extension’s Info.plist file, set the value for UNNotificationExtensionCategory under NSExtension > NSExtensionAttributes.

Build the UI Programmatically 

The MCExtensionSDK builds the notification UI programmatically. Configure your project to build the UI in code.

  1. Remove the storyboard reference by deleting the NSExtensionMainStoryboard item from Info.plist > NSExtension.

  2. Add the NSExtensionPrincipalClass key to Info.plist > NSExtension

    • Value type: String
    • Value: $(PRODUCT_MODULE_NAME).<MainClassName>

    For Objective-C projects, specify the class name directly.

    Note

  3. Remove MainInterface.storyboard from your project.

Turn On User Interaction 

Add this key to your content extension’s Info.plist file.

  • Key: UNNotificationExtensionUserInteractionEnabled
  • Value type: Boolean
  • Value: YES

This screenshot illustrates an Info.plist file in a Swift-based implementation with configured NSExtensionAttributes and NSExtensionPrincipalClass.

The details of the Info.plist file for a Swift-based implementation with configured NSExtensionAttributes and NSExtensionPrincipalClass

This screenshot illustrates an Info.plist file in an Objective-C-based implementation with configured NSExtensionAttributes and NSExtensionPrincipalClass.

The details of the Info.plist file for an Objective-C-based implementation with configured NSExtensionAttributes and NSExtensionPrincipalClass

Other Configuration Steps 

Implement the sfmcProvideConfig() method to define custom log levels and HTTP timeout settings.

View Swift code example
1import UIKit
2import UserNotifications
3import UserNotificationsUI
4import MCExtensionSDK
5
6class NotificationViewController: SFMCNotificationViewController {
7
8  override func sfmcProvideConfig() -> SFContentExtensionConfig {
9    var logLevel: LogLevel = .none
10  #if DEBUG
11    logLevel = .debug
12  #endif
13
14    return SFContentExtensionConfig(logLevel: logLevel, timeoutIntervalForRequest: 30.0)
15  }
16}
View Objective-C code example
1#import "NotificationViewController.h"
2
3@implementation NotificationViewController
4
5- (SFMCContentExtensionConfig *)sfmcProvideConfig {
6    SFMCExtensionSdkLogLevel logLevel = SFMCExtensionSdkLogLevelNone;
7#if DEBUG
8    logLevel = SFMCExtensionSdkLogLevelDebug;
9#endif
10    return [[SFMCContentExtensionConfig alloc] initWithLogLevel:logLevel timeoutIntervalForRequest:30.0];
11}

iOS blocks insecure (non-HTTPS) URLs by default. To load carousel images from HTTP URLs, configure an exception.

Note