puzzle-pieceNotification Service Extension

Use a Notification Service Extension to enable delivery tracking for ContextPush.

circle-exclamation

Overview

ContextPush requires a Notification Service Extension to track notification delivery when your app is not running. The extension allows iOS to wake a small piece of your code when a notification arrives, enabling delivery confirmation even when the main app is terminated.

Benefits:

  • Accurate delivery tracking and metrics

  • Context capture at notification delivery time

  • Better analytics for notification effectiveness

How Delivery Tracking Works

When you configure an appGroupIdentifier in your ContextSDK configuration, you are enabling delivery tracking. This tells ContextSDK that:

  1. Your app has a Notification Service Extension set up

  2. The extension will report traditional notification deliveries to ContextPush servers

triangle-exclamation

Prerequisites

Before setting up the extension, ensure you have:


Step 1: Create App Group

App Groups enable data sharing between your main app and the extension. Both need access to the same license verification token and shared data.

circle-info

App Group = Delivery Tracking Enabled: When you configure an App Group in your main app's Configuration, ContextSDK enables delivery tracking. This is why completing all steps in this guide is essential—skipping the extension implementation will cause inaccurate metrics.

1

Create an App Group Identifier

  1. Click the + button to create a new identifier

  2. Select App Groups and click Continue

  3. Enter a description and identifier (e.g., group.com.yourcompany.yourapp)

  4. Click Register

2

Enable App Groups in Your Main App

  1. Open your Xcode project

  2. Select your main app target

  3. Go to Signing & Capabilities

  4. Click + Capability and add App Groups

  5. Check the app group you created (or click + to add it)


Step 2: Create Notification Service Extension

1

Add Extension Target

  1. In Xcode, go to FileNewTarget

  2. Select Notification Service Extension

  3. Enter a name (e.g., NotificationServiceExtension)

  4. Click Finish

  5. If prompted to activate the scheme, click Cancel (you'll run the main app, not the extension directly)

2

Enable App Groups in Extension

  1. Select your extension target

  2. Go to Signing & Capabilities

  3. Click + Capability and add App Groups

  4. Check the same app group you added to the main app

circle-exclamation
3

Add ContextSDKExtension Dependency

Add the extension pod to your Podfile:

Then run:


Step 3: Configure Main App

Update your main app initialization to enable App Group support.

circle-exclamation
circle-info

The appGroupIdentifier must match exactly what you configured in both targets' capabilities.


Step 4: Implement Extension

Replace the contents of your NotificationService.swift with:

How It Works

  1. setupForExtension - Initializes the SDK using shared credentials from the App Group. Returns false if the main app hasn't been launched yet or license verification fails.

  2. handleNotification - Reports the notification to ContextPush servers for accurate reporting.

circle-exclamation

Troubleshooting

Extension Not Running

  • Verify App Groups are enabled in both targets

  • Check that both targets use the same App Group identifier

License Verification Fails

  • Launch the main app at least once after adding App Group support

  • Verify the license key is identical in both main app and extension

  • Check the App Group identifier matches exactly


Next Steps

Last updated

Was this helpful?