Platform Setup
Before using push notifications, complete the platform-specific setup:iOS
- In Xcode, enable the Push Notifications capability under your target’s Signing & Capabilities tab.
- Generate an APNs authentication key (.p8 file) in the Apple Developer Portal.
- Upload the .p8 key to the AppDNA Console under Settings > Push > iOS Configuration.
Android
- Set up Firebase Cloud Messaging (FCM) in your Android project.
- Add the
google-services.jsonfile to yourandroid/app/directory. - Upload the FCM server key to the AppDNA Console under Settings > Push > Android Configuration.
Push Module
Access the push module through theAppDNA.push accessor, which returns an AppDNAPushModule instance:
Request Permission
Request push notification permission from the user. This presents the system permission dialog and registers for remote notifications:bool indicating whether the user granted permission.
Set Token Manually
If you handle token registration yourself (e.g., usingfirebase_messaging), pass the token string to the SDK:
Get Current Token
Retrieve the currently registered push token:String? — null if no token has been registered.
Set Permission Status
Manually update the SDK with the current push permission status:Track Delivery and Taps
Track when a push notification is delivered to the device:AppDNAPushDelegate
Implement theAppDNAPushDelegate abstract class to receive push notification lifecycle callbacks:
Example Implementation
Legacy Stream API
The SDK also provides a legacy stream-based API through theAppDNAPush class for backward compatibility:
Request Permission (Legacy)
Push Received Stream
Listen for incoming push notifications via thecom.appdna.sdk/push_received EventChannel:
Push Tapped Stream
Listen for push notification taps via thecom.appdna.sdk/push_tapped EventChannel:
PushPayload
ThePushPayload class contains the notification content:
| Property | Type | Description |
|---|---|---|
pushId | String | Unique identifier for the notification |
title | String | Notification title |
body | String | Notification body text |
imageUrl | String? | URL to a rich notification image |
data | Map<String, dynamic>? | Custom data payload |
actionType | String? | Action type (e.g., “deep_link”, “url”) |
actionValue | String? | Action value (e.g., a URL or screen ID) |
Auto-Tracked Events
The SDK automatically tracks the following push-related events:| Event | Triggered When |
|---|---|
push_token_registered | Device token is successfully registered |
push_permission_granted | User grants push permission |
push_permission_denied | User denies push permission |
push_delivered | A push notification is delivered |
push_tapped | User taps on a push notification |
Auto-tracked events are sent alongside any manually tracked events. You do not need to track these events yourself.
Full Example
Push notification behavior varies between iOS and Android. On iOS, the system permission dialog is shown on first request. On Android 13+, the
POST_NOTIFICATIONS runtime permission is requested. The native SDKs handle these differences transparently.