- Setting up the Notification Service Extension (NSE): Enable rich media content (images, GIFs) and reliable impression tracking across all app states.
- Configuring the AppDelegate: Implement push notification registration, device token handling, and user interaction callbacks.
- Validating the Integration: Follow a process to test notification delivery, rich media display, and analytics tracking.
- Implementing Advanced Features: Enhance notifications with custom push templates, actionable buttons, and badge count control.
PrerequisitesTo enable push notifications:
- Integrate the MoEngage iOS SDK: Use CocoaPods, Swift Package Manager (SPM), or manual framework import as detailed in the MoEngage documentation.
- Configure APNs credentials in the MoEngage UI:
- MoEngage requires either an APNs Authentication Key (.p8) or an APNs Certificate (.pem) to communicate with Apple Push Notification Service (APNs).
- Recommendation: Use an APNs Authentication Key because it is non-expiring. Refer to the APNs Authentication Key Setup Guide.
- Ensure you have added Push Notifications capability in the main target by navigating to Target -> Signing & Capabilities.
Step 1: Implement Notification Service Extension (NSE)
NSE enables rich push notifications (including images, video, and GIFs) and tracks notification impressions across all app states.Create NSE Target
- In Xcode, navigate to File > New > Target… > Notification Service Extension.
- Enter a name for your NSE target.
Integrate MoEngageRichNotification
- SPM (Swift Package Manager)
- CocoaPods
To install the
MoEngageRichNotification through SPM, perform the following steps:- Navigate to File > Add Package.
- Enter the appropriate repository URL:
- https://github.com/moengage/apple-sdk.git (for MoEngage-iOS-SDK versions 9.23.0 and above)
- https://github.com/moengage/MoEngage-iOS-SDK.git (for other versions)
- Select the master branch or your desired version.
- Click Add Package.
- Target the installed package to your NSE file.
Set up App Group
To set up an App Group for seamless communication between your main app and NSE, perform the following steps:
-
Enable App Groups:
- For both your main application target and your NSE target, navigate to Signing and Capabilities.
- Click + Capability and select App Groups.
-
Create App Group ID:
- Create a new App Group ID (for example,
group.com.yourcompany.appname). - Crucially, ensure this exact App Group ID is enabled for both the main app and the NSE targets.
- Create a new App Group ID (for example,
-
Update AppDelegate: Modify your
AppDelegate.swiftin your iOS application to set the App Group ID as shown below:
Step 2: Implement Push Handling in AppDelegate
Integrate push notification registration and token management within yourAppDelegate to ensure proper communication with Apple Push Notification service (APNs) and MoEngage. This setup allows MoEngage to effectively map APNs tokens with your users.
Choose a Notification Registration Method
To register for remote notifications at launch, call exactly one of the following methods based on your desired user experience:- Standard Notifications (Direct Opt-In): Presents a system prompt for permission to deliver full notifications with banners and sounds upon user approval. Calling
registerForRemoteNotification()displays a permission pop-up to the user if they are not already opted in. - Provisional Notifications (Quiet Opt-In): Delivers notifications silently to the Notification Center without an initial prompt, allowing the user to opt into full delivery later.
- Provisional + Standard Push Notifications
- Standard Push Only
App Delegate Method Swizzling
App Delegate Method Swizzling, a runtime technique utilized by the MoEngage SDK, streamlines integration by automating push notification callback handling within the AppDelegate. The MoEngage SDK enables Method Swizzling by default to offer the quickest and most straightforward initial integration experience. To ensure maximum compatibility in applications that use other push-enabled SDKs, MoEngage provides a manual forwarding method. If you encounter conflicts, MoEngage recommends disabling the default Method Swizzling in the SDK settings. This manual approach requires you to forward the push payload directly to our SDK, giving you explicit control and ensuring that critical features like foreground notifications, click tracking, and deep links function reliably across all services.How to resolve App Delegate Swizzling conflicts?
How to resolve App Delegate Swizzling conflicts?
To resolve conflicts, disable MoEngage’s App Delegate Swizzling and manually forward push notification callbacks to the SDK.
-
Disable Swizzling: Add the following entry to your
Info.plistfile: -
Manual forwarding in AppDelegate: After disabling swizzling, implement the following code within your
AppDelegate.swiftfile to manually pass notification events to the MoEngage SDK:
Step 3: Validate Notifications
To ensure your MoEngage iOS Push Notification integration is fully functional, perform the following validation steps:Verify Dashboard Configuration
Before sending a test notification, first verify the integration status on your MoEngage dashboard. Navigate to the iOS Push section of your profile and confirm the following:- The integration status icon is green.
- For provisional authorization, the Opt-In Status is Unknown.
- For standard permission, the Opt-In Status is True.
Test Notification Delivery and Display
Send a Test Notification: From your MoEngage dashboard, create and send a test push notification that includes rich media (e.g., an image, GIF, or video).- Observe Device Behavior:
- Foreground: When your application is active (in the foreground), the notification should be displayed as a banner and accompanied by a sound.
- Background: If your application is in the background, the notification should still be delivered to the device and appear in the notification center.
- Killed State: Even when your application is force-closed or not running, the notification must be delivered and visible in the notification center.
- Rich Media Rendering: Verify that the rich media content within the notification (for example, the image) renders correctly across all app states (foreground, background, killed).
Tracking and Analytics Verification
- Access Campaign Analytics: Navigate to the analytics section of the push notification campaign you just sent within the MoEngage UI.
- Validate Impressions: Confirm that the “Impressions” metric for your campaign is incrementing. This indicates that the MoEngage SDK is successfully tracking when notifications are delivered and displayed on the device.
- Standard and Provisional Push Registration: Correct handling of user consent for push notifications.
- Reliable Delivery: Notifications are delivered and tracked in all application states: foreground, background, and killed.
- Rich Media Support: Enhanced notification experiences via the NSE, allowing for visually engaging content.
- Comprehensive Tracking: Accurate click and impression tracking across all app states, facilitated by the NSE, providing valuable campaign performance data.
Optional
After basic push notifications are implemented, enhance them with the following features.Push Templates
Create interactive, visually rich notifications by implementing two app extensions:- Notification Service Extension: Intercepts and modifies the notification payload before it is displayed. Use this to download and attach rich media, such as images or GIFs.
- Notification Content Extension: Renders a custom UI for the notification. Use this to create interactive experiences, such as image carousels or custom layouts.
Actionable Buttons
Embed buttons within a notification to allow users to perform tasks directly from the notification interface, such as “Reply” or “Archive.” For more information, refer here.Configure Push Notification Badge Behavior
WithdisableBadgeReset(true) enabled, the SDK won’t reset the badge to 0 on app launch. Instead, clicking a notification decrements the badge by 1, maintaining accurate counts when multiple notifications are present. Add the code snippet below post SDK initialization in AppDelegate.swift file:
Best Practices
Adhering to these best practices will ensure a robust and reliable push notification experience for your users and accurate data for your campaigns.- Test across all app states (Foreground, Background, Killed): This ensures consistent notification delivery, correct rich media rendering, and accurate tracking regardless of how the user is interacting with their device.
- If using provisional push, verify settings: Confirm the device’s notification settings show Deliver Quietly initially. Request the standard push permission and allow it. Then, go to Settings to confirm that the permission status is Authorized.
- Validate rich media URLs: Always check image/video URLs to prevent broken media displays and ensure the NSE can successfully attach content to your notifications.
FAQs
Why are my push notification clicks not being tracked, or why are my deep links not opening?
Why are my push notification clicks not being tracked, or why are my deep links not opening?
These symptoms typically indicate a “swizzling conflict” in your AppDelegate. This can happen if another third-party SDK is also managing push notification callbacks. To resolve this, you can disable MoEngage’s automatic swizzling and implement manual forwarding instead. Refer to the detailed instructions for the correct implementation.
Why is rich media (images, GIFs) not showing in my notifications, or why is impression tracking failing?
Why is rich media (images, GIFs) not showing in my notifications, or why is impression tracking failing?
This issue is commonly caused by an incorrect configuration of the NSE. Verify these three key areas:
- NSE Target Configuration: Ensure the
MoEngageNotificationServicetarget is correctly added to your project and is properly configured. - App Group ID: Confirm that the same App Group ID is enabled for both your main app and the NSE target, and that it has been correctly set in your code.
- Media URL Reachability: Check that the URLs for your images, GIFs, or videos are public and accessible. A broken URL will prevent the media from being downloaded and displayed.
- Ensure the deployment target of the extension matches the main app.
Why are push notifications not being delivered?
Why are push notifications not being delivered?
Verify the Bundle ID in Xcode matches the MoEngage UI. Ensure the APNs environment (Development or Production) matches the uploaded certificate type. Confirm your APNs certificate or auth key is valid. Test on a physical device; push notifications do not work on simulators.
Why is the didRegisterForRemoteNotificationsWithDeviceToken delegate method not called?
Why is the didRegisterForRemoteNotificationsWithDeviceToken delegate method not called?
Enable the Push Notifications capability in Xcode. Check for a stable internet connection and ensure no MDM or VPN profiles are blocking APNs ports. Verify another SDK is not intercepting APNs delegate callbacks.
Why are provisional push notifications not appearing?
Why are provisional push notifications not appearing?
Avoid requesting both standard and provisional authorization at launch. In the device’s Settings for your app, confirm “Deliver Quietly” is not enabled. By design, provisional notifications are delivered silently to the Notification Center without an alert or sound.