Notification Service Extension
Use a Notification Service Extension to enable delivery tracking for ContextPush.
Required for Delivery Tracking: The Notification Service Extension is required for accurate delivery tracking. Setting up an App Group without implementing this extension will result in inaccurate delivery metrics.
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:
Your app has a Notification Service Extension set up
The extension will report traditional notification deliveries to ContextPush servers
Important: If you set an appGroupIdentifier but do not implement the Notification Service Extension, your traditional delivery tracking data will be inaccurate, or messages maybe delivered multiple times.
Prerequisites
Before setting up the extension, ensure you have:
Completed the basic ContextPush integration
Xcode 14.0 or later
iOS 14.0 deployment target or higher
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.
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.
Create an App Group Identifier
Go to the Apple Developer Portal
Click the + button to create a new identifier
Select App Groups and click Continue
Enter a description and identifier (e.g.,
group.com.yourcompany.yourapp)Click Register
Step 2: Create Notification Service Extension
Step 3: Configure Main App
Update your main app initialization to enable App Group support.
Complete All Steps: Adding the appGroupIdentifier to your Configuration enables delivery tracking. You must also complete Step 4 (Implement Extension) for accurate metrics. ContextSDK will log a warning if it detects an App Group configuration without a Notification Service Extension.
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
setupForExtension- Initializes the SDK using shared credentials from the App Group. Returnsfalseif the main app hasn't been launched yet or license verification fails.handleNotification- Reports the notification to ContextPush servers for accurate reporting.
Important: The extension has limited execution time (~30 seconds). handleNotification is designed to complete quickly, but always implement serviceExtensionTimeWillExpire() as a fallback.
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
Review Analytics & Reporting to understand your reporting metrics
Check the Release Checklist before going to production
Last updated
Was this helpful?