There are many scenarios where you need to know if a user received a message - for example when building a fallback between push and email, or measuring how users react to a campaign. This article explains how notification delivery tracking works on iOS and Android.
Android
On Android, delivery tracking is handled automatically by the Pushwoosh SDK - you don't need a Notification Service Extension for it to work. A custom NotificationServiceExtension is only needed if you want to customize how a push is handled, for example suppressing the system notification while the app is in the foreground.
- Create a custom
NotificationServiceExtensionand include its fully qualified class name inAndroidManifest.xmlunder thecom.pushwoosh.notification_service_extensionmeta-data value:<meta-data android:name="com.pushwoosh.notification_service_extension" android:value="com.your.package.YourNotificationServiceExtension" /> - In
YourNotificationServiceExtension, overrideonMessageReceived:@Override protected boolean onMessageReceived(PushMessage message) { //handle push delivery here return false; //return true to suppress the system notification }
See the NotificationServiceExtension source for the full API.
iOS
Unlike Android, iOS does not track delivery out of the box - you must add a Notification Service Extension to your app for delivery tracking to work.
- Create a Notification Service Extension.
- Add a new target to your project (File -> New -> Target) and create a Notification Service Extension.
- Embed the new extension in your app. It has its own Bundle Id, Apple App ID and Provisioning Profile, which must be set up separately in the Apple Developer Portal. Make sure the extension supports arm64 (${ExtensionTarget} -> Build Settings -> Architectures).
- Implement
didReceiveNotificationRequestand hand the request to the Pushwoosh SDK:- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; [[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler]; }
Comments
0 comments
Please sign in to leave a comment.