Push Notification
This section covers how to setup push notification in React Native.
Enabling Push Notification in SDK
Set enablePush
to true
during SDK initialization. More details about SDK initialization can be found
here
Native setup
Step 1: Add required permissions
Add the following permission to android app AndroidManifest.xml
. This allows the app to receive push notifications
Step 2: Firebase push messaging handling service
By default SDK takes care of push token fetch and notification handling once app gets the permission to post notification.
In case the app has registered its own Firebase message service class (FirebaseMessagingService
) for handling push tokens,
SDK needs to be notified of the new token and any push notification received from Castled platform.
Folow these instructions
if you already have a FirebaseMessagingService
registered.
Step 3: Notification default configs
You can also configure default values for Notification Channels and Notification Icons. Please find the instructions here
Step 1: Add required permissions
Add the following permission to android app AndroidManifest.xml
. This allows the app to receive push notifications
Step 2: Firebase push messaging handling service
By default SDK takes care of push token fetch and notification handling once app gets the permission to post notification.
In case the app has registered its own Firebase message service class (FirebaseMessagingService
) for handling push tokens,
SDK needs to be notified of the new token and any push notification received from Castled platform.
Folow these instructions
if you already have a FirebaseMessagingService
registered.
Step 3: Notification default configs
You can also configure default values for Notification Channels and Notification Icons. Please find the instructions here
Step 1: Configure App Target for iOS Push
Follow these instructions for app target setup.
Ensure the appgroupId mentioned above matches the one enabled in the App Groups section of the Signing & Capabilities tab for all relevant targets in Xcode, including extensions. If App Groups are not enabled, there is no need to set an appgroupId.
We recommend configuring the appgroupId and using the Notification Service Extension for enhanced tracking of notification impressions, accurate badge counts, and media support.
Step 2: Configuring Notification Categories and Actions (Optional)
Apps are required to enable support for actionable notifications. During app launch, it is necessary to register one or more notification categories that define the types of notifications your app sends. Each category is associated with specific actions that users can take when receiving a notification of that type. While each category can have up to four actions, the actual number of displayed actions may vary depending on the notification display. For instance, banners typically show a maximum of two actions.
Registering the Notification Categories for Your App
By passing the notificationCategories parameter, you can define a set of categories and associated actions for your notifications. Each category corresponds to a type of notification that your app can receive, and for each category, you can specify the actions that a user can take directly from the notification.
This flexibility allows app developers to create a rich and interactive notification experience, tailored to the needs of their application and its users.
Step 3: Support for Rich Push Notification
Follow the instructions here for setting up rich push notifications.
Also in the /ios directory of your project, open the Podfile and add the following outside of the main target (should be at the same level as your main target):
We recommend configuring the appgroupId and using the Notification Service Extension for enhanced tracking of notification impressions, accurate badge counts, and media support.
Step 4: AppDelegate Swizzling in Castled SDK
Castled SDK is designed to simplify push notification handling. By default, swizzling is enabled, which means the SDK automatically handles the registration of device tokens, the presentation of notifications, and the response to user interactions with those notifications.
Disable Swizzling
This step is applicable only if:
- Your app is using other SDKs along with Castled for handling push notification.
- You prefer to have more granular control over notification handling or may need to comply with specific architectural requirements.
To disable method swizzling with Castled SDK, you must update the Info.plist file of your application.
Once swizzling is disabled, the responsibility of invoking the necessary methods falls on the developer.
Developer needs to implement various UNUserNotificationCenterDelegate
and UIApplicationDelegate
methods to handle
different notification scenarios.
Manual Handling of Push Notifications
Initializing Castled React SDK and Setting Delegates
If your Swift project doesn’t have a bridging header yet, you need to create one. To acheive this, Create a new Objective-C file in your Swift project. Xcode will prompt you to create a bridging header. Accept and let Xcode create it.
Handling Push Notifications Delegates (Copy Below Delegate Methods to AppDelegate)
If the App is handling the push notification click actions itself, please
disable the default url handling by the SDK by setting skipUrlHandling
to
true
in the SDK configs during initialization.
Requesting Push Notification Permission
Following SDK method can be used by the app to fetch user permission for showing push notifications. User will be shown the native notification permission dialog based on the mobile platform he is on.
Push Notification Events Listener
App can listen to push notification events by registering a listener. This is useful when you want to override the default click actions implemented by the SDK with your own custom implementations.
Currently the following push events as supported:
- Notification Received
- Notification Clicked
- Notification Dimissed
Please find the sample code snippet below
If the App is handling the push notification click actions itself, please
disable the default url handling by the SDK by setting skipUrlHandling
to
true
in the SDK configs during initialization.