Configure Push Notifications
Prerequisites
To get started, ensure the following prerequisites are met:
- Register your application on Firebase. To register, refer to this guide.
- Download the
google-services.json
file for Android and theGoogleService-Info.plist
file for iOS from your Firebase project. Do not make any code changes suggested by Firebase at this stage.
Configuring push notifications for Android
Follow these steps to configure push notifications for your Android project:
- Add the
google-services.json
file you downloaded from Firebase to theandroid/app
folder in your project. - Add the following class path in
dependencies classpath
in theandroid/build.gradle
file:'com.google.gms:google-services:4.4.2'
- In
android/app/build.gradle
, apply the following plugin at the top of the file, where other plugins are initialized:apply plugin: "com.google.gms.google-services"
- Add a
colors.xml
resource file in theandroid/app/src/main/res/values
folder if one does not already exist. Add the following color resource:<color name="hydra_notification_color">#FF03DAC5</color>
- Add a small icon file named
hydra_notification_small_icon
to theandroid/app/src/main/res/drawable
folder. This icon is used in the notification drawer. The file can be in XML, PNG, or JPG format.
Configuring push notifications for iOS
Follow these steps to configure push notifications for your iOS project:
- Add the
GoogleService-Info.plist
file you downloaded from Firebase to your iOS project using Xcode. - Ensure you have added the Push Notification capability for your app identifier on the Apple Developer website.
- In your Xcode project settings for your application target, add the following capabilities under Signing & Capabilities:
- Push Notification
- Background Modes, with Background fetch and Remote notifications enabled.
- In
HydraConfig.plist
, setSUPPORTS_PUSH_NOTIFICATION
toYES
.Note
It is mandatory to set up rich notifications for push notifications to function correctly on iOS. Refer to the instructions under Configure rich notifications for iOS for detailed steps.
Configuring rich notifications for iOS
Follow these steps to configure rich push notifications for your iOS project.
-
Go to your project settings in Xcode and add a new target and select Notification Service Extension from the available templates. This adds a Notification Service Extension to your project.
-
When configuring the new target, Xcode will append the
ProductName
of your main target to its bundle identifier to create the bundle identifier for this extension. You must add this extension bundle identifier on the Apple Developer website.

-
Select the language as
Objective-C
if yourAppDelegate
is Objective-C andSwift
if your AppDelegate is Swift. -
Add the
App Groups
capability inSigning & Capabilities
for both your main application target and the new extension target. You will need to create and add a group in both targets. The group name must follow the formatgroup.<runner_target_bundle_id>.hydra
, where<runner_target_bundle_id>
is replaced with the actual bundle identifier of your main application target. This App group also needs to be added on the Apple Developer website for both app identifiers. -
In your ios/Podfile, add
extension_pods
within the target block for your new extension target, as shown here:target 'HydraRichNotification' do extension_pods end
-
Install the pods again by opening your terminal, changing the current working directory to your project's ios folder, and running the command:
pod install
-
Replace the entire code
NotificationService.mm
(Objective-C) orNotificationService.swift
(Swift) with the following code:#import "NotificationService.h" #import "HydraPushNotificationServiceExtension/HydraPushNotificationServiceExtension.h" @implementation NotificationService HydraRemoteNotificationService* service; -(id)init{ self = [super init]; service = [[HydraRemoteNotificationService alloc] init]; return self; } - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { [service didReceiveNotificationRequest:request withContentHandler:contentHandler]; } - (void)serviceExtensionTimeWillExpire { [service serviceExtensionTimeWillExpire]; } @end
import UserNotifications import HydraPushNotificationServiceExtension class NotificationService: UNNotificationServiceExtension { let service:HydraRemoteNotificationService = .init() override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { service.didReceive(request, withContentHandler: contentHandler) } override func serviceExtensionTimeWillExpire() { service.serviceExtensionTimeWillExpire() } }
Updated about 8 hours ago