Learn how to integrate Firebase Cloud Messaging with Novu and send notifications to iOS
Set up an Apple platforms client
section.
.plist
file and put it in the root of your project.
info.plist
file.
->
Add Package Dependencies…`.
Paste that URL in the top right.
AppDelegates.swift
file.
Let’s import the “FirebaseCore” dependency by adding import FirebaseCore
to the beginning of the file.
Then, we will copy firebaseapp.configure()
and place it in didFinishLaunchingWithOptions
method.
Key ID
and Team ID
, which you can find in the top right corner.
AppDelegate.swift
file using the didFinishLaunchingWithOptions
method.
We paste this code block under firebaseApp.configure()
.
AppDelegate
extension at the bottom for UNUserNotificationCenterDelegate
.
import FirebaseMessaging
to the file.
Messaging.messaging().delegate = self
inside the didFinishLaunchingWithOptions
method.
AppDelegate.swift
file.
UNUserNotificationCenterDelegate
extension.didReceiveRemoteNotification
.gcmMessageIDKey
inside of AppDelegate
. We can define this as a string
variable.Background Modes
.
Push Notifications
capabilities.
notification title
and the notification text
, then we’re going to send the test message.
{{handlebars}}
variables for personalization.
This ensures consistent platform notifications and allows dynamic adjustments for individual subscribers, scenarios, and use cases.
Workflow creation is for streamlining automated notifications, enabling teams to communicate effectively without extensive technical expertise.
Nabigate to 'Workflows' tab and click on 'Blank Workflow'
Add (Drag & Drop) the Push channel node to the workflow
Click on the node, and start to modify the content. Once you are done, click on 'Update'
Creating a subscriber
Locating subscriber's FCM registration token
Adding the registration token to the subscriber
title
and the body
to {{title}}
and {{body}}
.
That way, we could insert values through the payload of the API call.10
.
Specify 10
to send the notification immediately.
Specify 5
to send the notification based on power considerations on the user’s device.
Specify 1
to prioritize the device’s power considerations over all other factors for delivery and prevent awakening the device.
NotificationService.swift
. This file is where you can customize notifications before the user sees them.
First, add the following import to the top of the file:
import FirebaseMessaging
Next, replace the contents of didReceive(_:withContentHandler:)
with the following:
FIRMessagingExtensionHelper
to perform all that work automatically in a straightforward helper method call.
Remember, iOS only allows you to download your attached image. If the extension’s code takes too long to run, the system will call serviceExtensionTimeWillExpire()
.
This gives you a chance to gracefully finish up anything you are doing in the extension or to simply present the notification as is, which is the default implementation.
This is the entire NotificationService.swift
file.
AppDelegate.swift
file, you should define the notification actions you want to add.
You can do this by creating a UNNotificationAction
for each action you want to include.
For example, let’s add two actions: “Accept” and “Reject”.
didFinishLaunchingWithOptions
method:
AppDelegate.swift
file should look like this: