Skip to content

About

A Notification Content Extension class to display custom content interfaces for iOS 10 push notifications

Topics

Resources

Stars

17 stars

Watchers

7 watching

Forks

Latest commit

 

History

426 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CTNotificationContent

Version SwiftPM compatible Platform iOS 15.0+ License

A Notification Content Extension class to display custom content interfaces for iOS 15 push notifications

Starting with iOS 10 you can add custom content views to iOS push notifications. This library provides a class to accomplish that. It provides a default Image Slideshow view and is designed to be easily extensible to display additional view types.

Custom push notification content interfaces are enabled in iOS 10 via a Notification Content Extension, a separate and distinct binary embedded in your app bundle.

Table of contents

Requirements

(Back to top)

  • Xcode 27 or later
  • iOS 15.0 or later

Xcode 27 refuses to build targets with a deployment target below iOS 15, which is why the minimum moved up from iOS 10. Note that this applies to your app target too: apps built against the iOS 26 or 27 SDK must adopt the UIScene lifecycle or iOS terminates them at launch. The sample apps in this repo show what that looks like. The content extension itself is unaffected, since extensions do not need a scene manifest.

🎉 Installation

(Back to top)

Swift Package Manager (recommended)

Swift Package Manager is an Xcode tool that installs project dependencies. To use it to install CTNotificationContent SDK, follow these steps:

  • In Xcode, navigate to File -> Swift Package Manager -> Add Package Dependency.
  • Enter https://github.com/CleverTap/CTNotificationContent.git when choosing package repo and Click Next.
  • On the next screen, Select an SDK version (by default, Xcode selects the latest stable version). Click Next.
  • Click Finish and ensure that the CTNotificationContent has been added to the app target.

NOTICE: CocoaPods trunk becomes read-only on December 2, 2026. After that date new CleverTap versions are published to our own specs repo, not to trunk. Add both source lines below to the top of your Podfile to keep receiving updates. The cdn.cocoapods.org line is still needed so other pods (for example SDWebImage) resolve. Existing installs are unaffected.

Your Podfile should look something like this:

source 'https://github.com/CleverTap/podspecs.git'
source 'https://cdn.cocoapods.org/'

platform :ios, '15.0'

use_frameworks!

target 'YOUR_NOTIFICATION_CONTENT_TARGET_NAME' do
    pod 'CTNotificationContent'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
    end
  end
end

The post_install hook is needed because platform :ios, '15.0' only sets a floor for pods that do not declare one themselves. Dependencies such as SDWebImage still ship a lower minimum, and Xcode 27 treats that as an error.

Then run pod install

See example Podfile here.

🚀 Setup

(Back to top)

Configure your app for Push and add a Notification Content Extension target

Enable push notifications in your main app.

Create a Notification Content Extension in your project. To do that in your Xcode project, select File -> New -> Target and choose the Notification Content Extension template.

notification content extension

Configure your Notification Content Extension to use the CTNotificationViewController class

Change the superclass of your NotificationViewController to CTNotificationViewController. You should not implement any of the UNNotificationContentExtension protocol methods in your NotificationViewController class, those will be handled by CTNotificationViewController. See Objective-C example here and Swift example here.

Edit the Maininterface.storyboard in your NotificationContent target to a plain UIView, see example here.

In your AppDelegate, register the Notification category and actions:

Swift:

    // register category with actions
    let action1 = UNNotificationAction(identifier: "action_1", title: "Back", options: [])
    let action2 = UNNotificationAction(identifier: "action_2", title: "Next", options: [])
    let action3 = UNNotificationAction(identifier: "action_3", title: "View In App", options: [])
    let category = UNNotificationCategory(identifier: "CTNotification", actions: [action1, action2, action3], intentIdentifiers: [], options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])

Objective-C:

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"action_1" title:@"Back" options:UNNotificationActionOptionNone];
    UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"action_2" title:@"Next" options:UNNotificationActionOptionNone];
    UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"action_3" title:@"View In App" options:UNNotificationActionOptionNone];
    UNNotificationCategory *cat = [UNNotificationCategory categoryWithIdentifier:@"CTNotification" actions:@[action1, action2, action3] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
    [center setNotificationCategories:[NSSet setWithObjects:cat, nil]];

See Objective-C example here and Swift example here.

Then configure your Notification Content target Info.plist to reflect the category identifier you registered: NSExtension -> NSExtensionAttributes -> UNNotificationExtensionCategory. In addition, set the UNNotificationExtensionInitialContentSizeRatio -> 0.1 and UNNotificationExtensionDefaultContentHidden -> true.

Also, If you plan on downloading non-SSL urls please be sure to enable App Transport Security Settings -> Allow Arbitrary Loads -> true in your plist. See plist example here.

Dashboard Usage

(Back to top) While creating a Push Notification campaign on CleverTap, just follow the steps below -

  1. On the "WHAT" section pass the desired required values in the "title" and "message" fields (NOTE: These are iOS alert title and body). Dashboard alert
  2. Click on "Advanced" and then click on "Rich Media" and select Single or Carousel template. Dashboard Rich Media
  3. For adding custom key-value pair, add the template Keys individually or into one JSON object and use the pt_json key to fill in the values. Dashboard Custom Key individual Dashboard Custom Key JSON
  4. Send a test push and schedule!

Troubleshooting

(Back to top)

If you encounter issues while rendering a template, refer to the Debug Guide for common problems and their resolutions.

Template Types

(Back to top)

Rich Media

Single Media

Single media is for basic view with single image. Single Media

Content Slider

Content Slider is for image slideshow view where user can add multiple images with different captions, sub-captions, and actions.

Content slider

Custom key-value pair

Basic Template

Basic Template is the basic push notification received on apps where user can also update text colour, background colour.

Custom Basic template

Auto Carousel Template

Auto carousel is an automatic revolving carousel push notification where user can also update text colour, background colour.

Auto carousel

Manual Carousel Template

This is the manual version of the carousel. The user can navigate to the next/previous image by clicking on the Next/Back buttons.

NOTE:

For iOS 12 and above, you need to configure your Notification Content target Info.plist to reflect the category identifier you registered: NSExtension -> NSExtensionAttributes -> UNNotificationExtensionCategory. In addition, set the UNNotificationExtensionInitialContentSizeRatio -> 0.1 , UNNotificationExtensionDefaultContentHidden -> true and UNNotificationExtensionUserInteractionEnabled -> 1.

For iOS 11 and below, the previous/next buttons will not work. Please use notification actions with identifiers action_1 and action_2 for this purpose.


Manual carousel

Timer Template

This template features a live countdown timer. You can even choose to show different title, message, and background image after the timer expires.

Timer template

Zero Bezel Template

The Zero Bezel template ensures that the background image covers the entire available surface area of the push notification. All the text is overlayed on the image.

Zero Bezel template

Rating Template

Rating template lets your users give you feedback.

NOTE:

For iOS 12 and above, you need to configure your Notification Content target Info.plist to reflect the category identifier you registered: NSExtension -> NSExtensionAttributes -> UNNotificationExtensionCategory. In addition, set the UNNotificationExtensionInitialContentSizeRatio -> 0.1 , UNNotificationExtensionDefaultContentHidden -> true and UNNotificationExtensionUserInteractionEnabled -> 1. For iOS 11 and below, it will fallback to a basic template.


Rating

Product Catalog Template

Product catalog template lets you show case different images of a product (or a product catalog) before the user can decide to click on the "BUY NOW" option which can take them directly to the product via deep links. This template has two variants.

NOTE:

For iOS 12 and above, you need to configure your Notification Content target Info.plist to reflect the category identifier you registered: NSExtension -> NSExtensionAttributes -> UNNotificationExtensionCategory. In addition, set the UNNotificationExtensionInitialContentSizeRatio -> 0.1 , UNNotificationExtensionDefaultContentHidden -> true and UNNotificationExtensionUserInteractionEnabled -> 1. For iOS 11 and below, it will fallback to a basic template.


Vertical View

Product Display

Linear View

Use the following keys to enable linear view variant of this template.

Template Key Required Value
pt_product_display_linear Optional true

Product Display

WebView Template

WebView template lets you load a remote https URL.

WebView Template

Note: If any image can't be downloaded, the template falls back to basic template with caption and sub caption only.

Template Keys

(Back to top)

Rich Media

Content Slider

Configure your APNS payload:

Then, when sending notifications via APNS:

  • include the mutable-content flag in your payload aps entry (this key must be present in the aps payload or the system will not call your app extension)
  • for the Image Slideshow view, add the ct_ContentSlider key with a json object value, see example below, to the payload, outside of the aps entry.
{

    "aps": {
        "alert": {
            "body": "test message",
            "title": "test title",
        },
        "category": "CTNotification",
        "mutable-content": true,
      },
    "ct_ContentSlider": {
        "orientation": "landscape", // landscape assumes 16:9 images, remove to display default square/portrait images
        "showsPaging": true, // optional to display UIPageControl
        "autoPlay": true, // optional to auto play the slideshow
        "autoDismiss": true, // optional to auto dismiss the notification on item actionUrl launch
        "items":[
            {
                "caption": "caption one",
                "subcaption": "subcaption one",
                "imageUrl": "https://s3.amazonaws.com/ct-demo-images/landscape-1.jpg",
                "actionUrl": "com.clevertap.ctcontent.example://item/one"
            }, 
            {
                "caption": "caption two", 
                "subcaption": "subcaption two", 
                "imageUrl": "https://s3.amazonaws.com/ct-demo-images/landscape-2.jpg",
                "actionUrl": "com.clevertap.ctcontent.example://item/two"
            }
       ]
   }
}

Custom key-value pair

Basic Template

Basic Template Keys Required Description
pt_id Required Value - pt_basic
pt_title Required Title
pt_msg Required Message
pt_msg_summary Required Message line when Notification is expanded
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color for dark mode in HEX
pt_big_img Optional Image
pt_gif Optional GIF
pt_big_img_alt_text Optional Alt Text for Image
pt_dl1 Optional One Deep Link
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_img_corner_radius Optional Image corner radius as a percentage of the image height (numeric or string)
pt_img_border_width Optional Image border width as a percentage of the notification height, where 10 is 1% (numeric or string)
pt_img_border_clr Optional Image border color in HEX. Applies only when pt_img_border_width is set
pt_json Optional Above keys in JSON format

Auto Carousel Template

Auto Carousel Template Keys Required Description
pt_id Required Value - pt_carousel
pt_title Required Title
pt_msg Required Message
pt_msg_summary Optional Message line when Notification is expanded
pt_dl1 Required Deep Link for first image
pt_dl2 Optional Deep Link for second image (defaults to pt_dl1)
pt_dl3 Optional Deep Link for third image (defaults to pt_dl1)
pt_img1 Required Image One
pt_img1_alt_text Optional Alt Text for Image One
pt_img2 Required Image Two
pt_img2_alt_text Optional Alt Text for Image Two
pt_img3 Required Image Three
pt_img3_alt_text Optional Alt Text for Image Three
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color for dark mode in HEX
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_img_corner_radius Optional Image corner radius as a percentage of the image height (numeric or string)
pt_img_border_width Optional Image border width as a percentage of the notification height, where 10 is 1% (numeric or string)
pt_img_border_clr Optional Image border color in HEX. Applies only when pt_img_border_width is set
pt_json Optional Above keys in JSON format

Manual Carousel Template

Manual Carousel Template Keys Required Description
pt_id Required Value - pt_manual_carousel
pt_title Required Title
pt_msg Required Message
pt_msg_summary Optional Message line when Notification is expanded
pt_dl1 Required Deep Link for first image
pt_dl2 Optional Deep Link for second image (defaults to pt_dl1)
pt_dl3 Optional Deep Link for third image (defaults to pt_dl1)
pt_img1 Required Image One
pt_img1_alt_text Optional Alt Text for Image One
pt_img2 Required Image Two
pt_img2_alt_text Optional Alt Text for Image Two
pt_img3 Required Image Three
pt_img3_alt_text Optional Alt Text for Image Three
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color for dark mode in HEX
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_img_corner_radius Optional Image corner radius as a percentage of the image height (numeric or string)
pt_img_border_width Optional Image border width as a percentage of the notification height, where 10 is 1% (numeric or string)
pt_img_border_clr Optional Image border color in HEX. Applies only when pt_img_border_width is set
pt_json Optional Above keys in JSON format

Timer Template

Timer Template Keys Required Description
pt_id Required Value - pt_timer
pt_title Required Title
pt_title_alt Optional Title to show after timer expires
pt_msg Required Message
pt_msg_alt Optional Message to show after timer expires
pt_msg_summary Optional Message line when Notification is expanded
pt_dl1 Required Deep Link
pt_big_img Optional Image
pt_gif Optional GIF
pt_big_img_alt_text Optional Alt Text for Image
pt_big_img_alt Optional Image to show when timer expires
pt_gif_alt Optional GIF to show when timer expires
pt_big_img_alt_alt_text Optional Alt Text for Image to show when timer expires
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color for dark mode in HEX
pt_chrono_title_clr Optional Color for timer text in HEX
pt_chrono_title_clr_dark Optional Color for timer text for dark mode in HEX
pt_timer_threshold Required Timer duration in seconds. Will be given higher priority.
pt_timer_end Optional Epoch Timestamp to countdown to (for example, $D_1595871380 or 1595871380). Not needed if pt_timer_threshold is specified.
pt_chrono_bg_clr Optional Timer box background color in HEX (light mode)
pt_chrono_bg_clr_dark Optional Timer box background color in HEX (dark mode)
pt_chrono_style Optional Timer box background style: solid (default), gradient_linear, or gradient_radial
pt_chrono_grad_clr1 Optional Gradient start color in HEX (used when pt_chrono_style is a gradient type)
pt_chrono_grad_clr2 Optional Gradient end color in HEX (used when pt_chrono_style is a gradient type)
pt_chrono_grad_dir Optional Linear gradient direction in degrees (default 90). Only applies to gradient_linear style
pt_chrono_border_clr Optional Timer box border color in HEX (light mode)
pt_chrono_border_clr_dark Optional Timer box border color in HEX (dark mode)
pt_chrono_border_width Optional Timer box border width in points (numeric or string, max 10)
pt_chrono_border_radius Optional Timer box corner radius in points (numeric or string, max 25)
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_img_corner_radius Optional Image corner radius as a percentage of the image height (numeric or string)
pt_img_border_width Optional Image border width as a percentage of the notification height, where 10 is 1% (numeric or string)
pt_img_border_clr Optional Image border color in HEX. Applies only when pt_img_border_width is set
pt_json Optional Above keys in JSON format

Timer State Persistence: The countdown correctly reflects elapsed time since notification delivery when the notification is expanded. To enable this, set the notificationDeliveryDate property on CTTimerTemplateController to the notification's delivery timestamp.

Zero Bezel Template

Zero Bezel Template Keys Required Description
pt_id Required Value - pt_zero_bezel
pt_title Required Title
pt_msg Required Message
pt_msg_summary Optional Message line when Notification is expanded
pt_subtitle Optional Subtitle
pt_big_img Required Image
pt_gif Optional GIF
pt_big_img_alt_text Optional Alt Text for Image
pt_dl1 Required Deep Link
pt_title_clr Optional Title Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr Optional Message Color in HEX
pt_json Optional Above keys in JSON format

Rating Template

Rating Template Keys Required Description
pt_id Required Value - pt_rating
pt_title Required Title
pt_msg Required Message
pt_big_img Optional Image
pt_gif Optional GIF
pt_big_img_alt_text Optional Alt Text for Image
pt_msg_summary Optional Message line when Notification is expanded
pt_subtitle Optional Subtitle
pt_default_dl Required Default Deep Link for Push Notification
pt_dl1 Required Deep Link for first/all star(s)
pt_dl2 Optional Deep Link for second star
pt_dl3 Optional Deep Link for third star
pt_dl4 Optional Deep Link for fourth star
pt_dl5 Optional Deep Link for fifth star
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color in HEX
pt_ico Optional Large Icon
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_img_corner_radius Optional Image corner radius as a percentage of the image height (numeric or string)
pt_img_border_width Optional Image border width as a percentage of the notification height, where 10 is 1% (numeric or string)
pt_img_border_clr Optional Image border color in HEX. Applies only when pt_img_border_width is set
pt_json Optional Above keys in JSON format

Product Catalog Template

Product Catalog Template Keys Required Description
pt_id Required Value - pt_product_display
pt_title Required Title
pt_msg Required Message
pt_subtitle Optional Subtitle
pt_img1 Required Image One
pt_img1_alt_text Optional Alt Text for Image One
pt_img2 Required Image Two
pt_img2_alt_text Optional Alt Text for Image Two
pt_img3 Optional Image Three
pt_img3_alt_text Optional Alt Text for Image Three
pt_bt1 Required Big text for first image
pt_bt2 Required Big text for second image
pt_bt3 Required Big text for third image
pt_st1 Required Small text for first image
pt_st2 Required Small text for second image
pt_st3 Required Small text for third image
pt_dl1 Required Deep Link for first image
pt_dl2 Required Deep Link for second image
pt_dl3 Required Deep Link for third image
pt_price1 Required Price for first image
pt_price2 Required Price for second image
pt_price3 Required Price for third image
pt_bg Optional Background Color in HEX
pt_bg_dark Optional Background Color for dark mode in HEX
pt_product_display_action Required Action Button Label Text
pt_product_display_linear Optional Linear Layout Template ("true"/"false")
pt_product_display_action_clr Required Action Button Background Color in HEX
pt_product_display_action_clr_dark Required Action Button Background Color for dark mode in HEX
pt_title_clr Optional Title Color in HEX
pt_msg_clr Optional Message Color in HEX
pt_title_clr_dark Optional Title Color for dark mode in HEX
pt_msg_clr_dark Optional Message Color for dark mode in HEX
pt_json Optional Above keys in JSON format

WebView Template

WebView Template Keys Required Description
pt_id Required Value - pt_web_view
pt_dl1 Required Deep Link
pt_url Required URL to load
pt_orientation Optional Value - landscape or portrait
pt_json Optional Above keys in JSON format

Sample App

(Back to top)

Debug Logs

(Back to top)

The SDK can write logs to the unified logging system. They are off by default, so updating the SDK adds nothing to your device logs until you turn them on. The level values are the same as the CleverTap iOS SDK's CleverTapLogLevel:

Level What you get
-1 (default) Nothing.
0 A short trail for each push: which template was picked, what it fell back to and why, and every error. No line at this level holds payload values or notification text. A url shows only its scheme and host, for example url=https://cdn.example.com [rest hidden].
1 Everything from 0, plus the whole payload, full urls including deeplinks, each image download, and layout details.

The SDK does not switch levels by build configuration itself. Set the level in your Notification Content Extension, not in the app, because the extension runs in its own process and has its own copy of the setting. Call it before super.viewDidLoad():

import CTNotificationContent

class NotificationViewController: CTNotificationViewController {
    override func viewDidLoad() {
        #if DEBUG
        CTContentLog.setDebugLevel(1)
        #endif
        super.viewDidLoad()
    }
}
#import <CTNotificationContent/CTNotificationContent-Swift.h>

- (void)viewDidLoad {
#ifdef DEBUG
    [CTNotificationContentLogger setDebugLevel:1];
#endif
    [super viewDidLoad];
}

To keep a short trail in release builds too, so a problem that already happened on a device can still be read afterwards, call setDebugLevel(0) outside the #if DEBUG block.

Level 1 writes whole payloads and full urls into the device log, and those lines stay on disk just like the level 0 ones. Keep it inside #if DEBUG, as above, so it does not reach a release build.

A Notification Content Extension runs in its own process, so print output does not reach the Xcode console unless you attach to that process. The commands below do not need Xcode.

Connect the device to a Mac and run:

log stream --predicate 'subsystem == "com.clevertap.sdk"'

To read logs the device already recorded, instead of watching new ones:

log show --predicate 'subsystem == "com.clevertap.sdk"' --last 30m

The subsystem is shared with the CleverTap iOS SDK, so both commands show logs from both SDKs. To see only this SDK, add the category:

log stream --predicate 'subsystem == "com.clevertap.sdk" AND category == "CTNotificationContent"'

Every line looks like this:

[CleverTap][CTNotificationContent] CTCarouselController.createView(): No image or gif in payload, rendering title and message

[CleverTap] is the prefix the CleverTap iOS SDK also uses. [CTNotificationContent] marks the lines that come from this SDK, and matches the category above. The part before the colon is the type and the function the line came from.

You can also use Console.app instead of the commands above. Select the device in the sidebar, then put subsystem:com.clevertap.sdk in the search field. Choose Action > All Messages. The Errors and Faults view hides these logs.

When you report a problem to CleverTap, please attach the output of the log show command above.

Changelog

(Back to top) Refer to the Change Log.

About

A Notification Content Extension class to display custom content interfaces for iOS 10 push notifications

Topics

Resources

Stars

17 stars

Watchers

7 watching

Forks

Releases

Contributors

Languages