Prerequisites
To complete this tutorial, you will need the following:- Apple Developer membership (to obtain the required permissions to send push notifications)
- A machine running MacOS to work on an iOS project
- Firebase account
- Novu account
- Xcode installed on your machine
Create an iOS app
Open Xcode and create a new project, choosing the App template. Give your project a name, and select your name as the team for now, or leave it blank. Your bundle identifier will be generated here — you will use this later when connecting to Firebase. Select SwiftUI as your interface and Swift as your language.






Set up an Apple platforms client
section.





Create a Firebase project
Select a name for your project.






.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.





Create and upload our APNs authentication key
We will create and upload our APNs authentication key to the Firebase project settings.








Key ID
and Team ID
, which you can find in the top right corner.


Register for Remote Notifications

-
Copy this code block and place it inside the
AppDelegate.swift
file using thedidFinishLaunchingWithOptions
method. We paste this code block underfirebaseApp.configure()
. -
We need to conform to this delegate, so we will also create an
AppDelegate
extension at the bottom forUNUserNotificationCenterDelegate
. -
Add
import FirebaseMessaging
to the file.
Access the Registration Token
To do this, we must first set theMessaging.messaging().delegate = self
inside the didFinishLaunchingWithOptions
method.


AppDelegate.swift
file.

Receive messages in an Apple App
- Copy this code block and place it in
UNUserNotificationCenterDelegate
extension. - Add the
didReceiveRemoteNotification
. - We must declare a
gcmMessageIDKey
inside ofAppDelegate
. We can define this as astring
variable.

Adding app capabilities

Background Modes
.

- Background Fetch
- Remote Notifications
- Background Processing

Push Notifications
capabilities.

App Build


Cloud Message Test
In your Firebase project, navigate to ‘engage’ section and click on ‘messaging’.


notification title
and the notification text
, then we’re going to send the test message.






Novu account creation


Connecting FCM as a provider


- Select your project. Click the gear icon on the top of the sidebar.
- Head to project settings.
- Navigate to the service account tab.
- Click “Generate New Private Key”, then confirm by clicking “Generate Key”.
- Clicking Generate Key will download the JSON file.
- Once the file is on your machine, paste the entire JSON file content in the Service Account field of the FCM provider in the integration store on Novu’s web dashboard.





Creating a workflow
In Novu, creating a workflow means establishing a blueprint for sending notifications within your app. This unified structure ties together email, in-app messages, SMS, push notifications, and chat into one entity. Each workflow has a unique name and identifier and includes customized content for various channels, using{{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.
1
Nabigate to 'Workflows' tab and click on 'Blank Workflow'


2
Add (Drag & Drop) the Push channel node to the workflow

3
Click on the node, and start to modify the content. Once you are done, click on 'Update'

Creating a subscriber
Creating a subscriber in Novu refers to the process of establishing a subscriber entity within the Novu platform. A subscriber is essentially the recipient of the notifications sent through Novu’s system. When you create a subscriber, you’re setting up the necessary information for Novu to send targeted notifications to that individual.
1
Creating a subscriber

2
Locating subscriber's FCM registration token

3
Adding the registration token to the subscriber
Subscriber can have multiple device tokens

Sending a notification to iOS device with Novu
To send a notification with Novu, you are actually triggering a notification workflow. You have the ability to test the trigger using the user interface or by calling Novu’s API. Trigger a workflow via the API
Dynamic Content
When we were creating the first workflow, we “Hardcoded” the content of the notification. Now, we will determine the content when calling the API.- In the workflow, we should change the values of the
title
and thebody
to{{title}}
and{{body}}
. That way, we could insert values through the payload of the API call.

- Add a ‘payload’ object to the API call.

Sound of a notification
The name of a sound file in your app’s main bundle or in the Library/Sounds folder of your app’s container directory. Specify the string “default” to play the system sound. Use this key for regular notifications. For critical alerts, use the sound dictionary instead.Priority for notification
If you omit this header, APNs set the notification priority to10
.
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.
Sending images
Up to this point, your notifications have all contained only text. But if you’ve received many notifications, you know that notifications can have rich content, such as images. It’d be great if your notifications showed users a nice image related to their content. Once again, Firebase makes this super simple. To show an image in push notifications, you’ll need to create a Notification Service Extension. This is a separate target in your app that runs in the background when your user receives a push notification. The service extension can receive a notification and change its contents before iOS shows the notification to the user. You’ll use Firebase to send an image URL inside a notification. You’ll then use a content extension to download the image and add it to the notification’s content. In Xcode, go to File ▸ New ▸ Target…. Search for Notification Service Extension and select Next. Set a name and configure it to add to your main project.






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.

- “mutable-content”: 1 inside the “aps” object.
- “image” in “fcm_options” object,
- URL address of the image.


Sending actionable notifications
- Define Notification Actions:
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”.
-
Register Notification Category:
You need to register the notification category with the actions you defined in your
didFinishLaunchingWithOptions
method:
AppDelegate.swift
file should look like this:
