Push Notifications for React Native apps
By now, you would have already integrated Apptics if you are using any other module. If not, refer to the integration guide.
Push notifications are available in React Native version 0.10.0-beta.1.
iOS setup
- Import and initialize in a notification service extension.
- Specify the pod 'AppticsNotificationServiceExtension' in your podfile.
- The podfile will look something similar to the one below.
Copied
Show full
Show less
Note: Pass the common app group identifier --app-group-identifier="group.MAIN_BUNDLE_IDENTIFIER.apptics" to the run script as mentioned in the above sample podfile.
- From your terminal, navigate to the iOS folder and run pod install --repo-update.
- Open the .xcworkspace file in Xcode.
- Go to your root project in Xcode and select the main app target. Navigate to the Signing & Capabilities tab.
- If push notifications are not enabled, click + Capability and add push notifications.
- Click + Capability again and add Background modes.
- Also, enable the remote notifications.
Add notification service extension
The AppticsNotificationServiceExtension enables your iOS app to receive the rich notifications with images, buttons, and badges. It is also essential for Apptics' confirmed devliery analytics stats.
- In Xcode, navigate to File > New > Target.
- Select the Notification Service Extension and click Next.
- Give a name to the NotificationServiceExtension and click Finish.
- When prompted to activate the scheme after selecting Finish, click Cancel to avoid activating it.
- In Xcode, select the NotificationServiceExtension target.
- Go to general settings. Set the minimum deployment to match your main application target. This should be iOS 14.5 or higher.
Add app groups
App groups enable your app and the NotificationServiceExtension to share data when a notification is received, even if the app is not running. This is essential for implementing the badges and confirmed deliveries.
- Select your main app target in Xcode.
- Go to Signing & Capabilities and click on + Capability.
- Choose App groups.
- Click on + to add a new group.
- Set the app groups container name to 'group.MAIN_BUNDLE_IDENTIFIER.apptics', where the MAIN_BUNDLE_IDENTIFIER should match the bundle identifier of your main application.
- Click OK to save the app group for your main app target. Repeat the steps for the NotificationServiceExtension Target.
- Select the NotificationServiceExtension Target > Signing & Capabilities > + Capability > App groups.
- In app groups, click + button to add a new group.
- Set the app group container to 'group.MAIN_BUNDLE_IDENTIFIER.apptics', making sure NOT to include 'NotificationServiceExtension' in the name.
- Replace the MAIN_BUNDLE_IDENTIFIER with the bundle identifier of your main application.
Integrate the notification service extension
- In the Xcode project navigator, select the NotificationServiceExtension folder.
- Locate and open the NotificatioService.m (for Obj-C) or NotificationService.swift (for Swift) file.
- Replace the whole content of the file with the following code.
Upload p12 certificate
Refer to this link for detailed steps on how to upload your p12 certificate to Apptics.
Android setup
Make sure that you have configured the Firebase credentials in the Apptics web console. Refer to this link.
- Add Apptics push dependency to your app level build.gradle (android/app/build.gradle).
Copied
- Add Apptics push messaging service to your app's manifest (android/app/src/main/Android.Manifest.xml).
Copied
Initialization
- Initialize Apptics push notification service in your app.js or index.js.
Copied
- Register push notification from React Native for iOS applications.
Copied
Android notification customizations
Notification channel
Starting from Android 8 (Oreo) and above, apps must assign a notification channel for every notification. You can configure the notification channel for push notifications sent by Apptics through the Notification Builder in Apptics web console when publishing a notification.
You can also configure a default channel ID as meta-data in your AndroidManifest.xml, which will be used if no notification channel is specified in the Notification Builder.
Copied
Apptics SDK posts notification with a built-in channel if no channel ID is configured.
Notification icon
Notification icon (small) can be configured from the Apptics web console when publishing a notification.
You can also configure a default icon as the meta-data in your AndroidManifest.xml which will be used if notification icon is not available in the incoming message.
Copied
If both the default icon and icon from the incoming messages are not available, App icon will be used.
Notification color
Notification color can be configured from the Apptics web console when publishing a notification.
You can also configure a default color as the meta-data in your AndroidManifest.xml which will be used if the color is not available in the incoming message.
Copied
Notification sound
From Android 8 (Oreo) and above, notification sounds are based on the notification channels. Apptics doesn't provide any default notification channels. Refer to Notification channels to assign channels to notifications sent by Apptics.
For Android 7 and below, you can configure the notification sound from the Apptics web console while publishing the notification.
Add your custom sound file in res/raw folder and provide the name of the file with extension in additional info while publishing notification.
Note: .3gp, .mp4, .wav are some of the supported container formats.