Skip to content

Push Notifications let you deliver time-sensitive, real-time messages to users even when the app isn’t active. These notifications rely on Firebase Cloud Messaging (FCM) behind the scenes, which routes messages to both Android and iOS devices. When integrated correctly, you can use push notifications to:

  • Send alerts for new content (e.g., chat messages, and updates).
  • Re-engage users with timely reminders or offers.
  • Provide relevant information (e.g., order status, location-based alerts).

Push notifications involve several key components working together to deliver messages to users’ devices. In FlutterFlow Studio, you can construct and send notification payloads—such as title, message body, and additional data like image—to a push service, Firebase Cloud Messaging (FCM). FCM receives notifications and routes them to the appropriate devices.

Each device is identified by a unique Device Token/Registration Token generated by the FCM to target specific devices. The user’s device receives these notifications and handles the payload by displaying messages or navigating the user to specific screens.

Push Notifications Setup

You can add and send push notifications manually or trigger them based on user actions within the app. Here are the steps in detail:

Enabling Push Notification

To enable push notifications:

  1. Navigate to the Settings and Integrations > Push Notifications and Enable Push Notifications.
  2. Now, click on the Deploy button. This will create and deploy the Cloud Functions in your Firebase project that are necessary for push notifications to work.
  3. Optionally, you can enable Allow Scheduling to send push notifications at a later time. Once enabled, you can select Scheduler Granularity, which determines how precisely the notifications will be sent. You can choose the granularity based on how time-sensitive your notifications are; For example:
    • If you need the notification to be sent at an exact time (e.g., 11:37 AM), choose “1 minute”.
    • If a slight delay is acceptable, you can select “15 minutes” or “1 hour”, meaning the notification will be sent within that timeframe.
    • Higher precision (e.g., 1-minute intervals) requires more computing resources, which may slightly increase costs (up to $0.50 per month).
    • Lower precision (e.g., 1-hour intervals) is more cost-effective, as it reduces the frequency of function execution (around $0.05 per month).

img.png

Configuring iOS App

To receive the push notifications in an iOS app, you need to perform the following additional steps.

Step 1: Creating a Key

Apple requires developers to create a key for the push notifications inside the Apple Developer Console to verify the push notification’s sender.

To create an APNs key in your Apple Developer account, go to the Keys section and click the (+) button. Enter a Key Name, select Apple Push Notifications service (APNs), and click Configure. Choose the appropriate Environment (Sandbox, Production, or both) and set any Key Restriction as needed. Once configured, click Save, then Continue and Register. Finally, download and securely store the key file, as it will be required for integration with your Firebase project.

Step 2: Add APNs Key to Firebase Project

To add the APNs key to your Firebase project, navigate to your Firebase Project Dashboard > Project Settings and select the Cloud Messaging tab. Scroll down to the Apple app configuration section and locate the APNs Authentication Key.

Click Upload and select your APNs auth key file (that you downloaded in the previous step). Enter the Key ID, which can be found inside the key entry in Keys. Finally, enter the Team ID, available in the Apple Developer Account inside the Membership details section.

Send Push Notifications

To send push notifications, go to FlutterFlow Studio > Settings and Integrations > Push Notifications, then open the Manually Trigger Notifications section. Enter the notification details and click Send Notification. A confirmation popup will appear—type “Send Notification” and click Send Notification again to deliver your message.

To send push notifications, you need to provide the following details:

  • Notification Title: Enter the title of the notification.

  • Notification Text: Provide the message content for the notification.

  • Notification Image (Optional): Upload an image to be displayed with the notification.

  • Target Audience (Optional): Choose whether to send notifications to iOS, Android users, or All users regardless of their device type.

  • Deliver With Sound (Optional): Enable this option if you want the notification to play a sound.

  • Batch Notifications (Optional): Toggle this setting if you want to send the notification in batches. Enable this only when you have over 10K users.

  • Scheduled Time (Optional): Choose the specific date and time for the notification to be sent. This option is available only when the Allow Scheduling option is enabled, and the selected date and time follow your timezone.

  • User References (Optional): Send push notifications to a specific user or a few users. Enter the user document reference (from the ‘users’ collection in Firestore) into the User References in this format: /users/user_id.

  • Initial Page (Optional): Choose the page the app should open when the user taps the notification.

Push Notifications with Data

Sometimes, you might want to include additional data with your push notifications, which can then be used to display more detailed information on the page when it is opened through a push notification.

For instance, consider a news app that sends push notifications for breaking news. When the user taps the notification, the additional data like the article’s title, summary, and image can be displayed on the news page.

To send a push notification with data, you need a page that accepts a parameter of type DocumentReference. Start by building the notification, and set the Initial Page to the one that accepts the parameter. In the Parameter Data section, copy-paste the document reference from Firestore. Finally, click Send Notification to deliver the push notification with the specified data.

pn-with-data.avif

Trigger Push Notification [Action]

You may want to send a push notification when a specific event occurs in your app. For example, notifying a user when they receive a new message, when an appointment is booked, or when there is a price change.

You can send the push notification when such an event occurs by adding the Trigger Push Notification action.

In this action, you can decide who should receive the push notification by setting the Audience to either Single Recipient or Multiple Recipients.

  • Single Recipient: Sends a notification to one specific user. For example, notifying the group creator when a new member joins.
  • Multiple Recipients: Sends a notification to multiple users. For example, notifying all group members when someone joins the group.

trigger push notifications

Testing Push Notifications Cloud Function

You can also test the Push Notifications Cloud Function directly from the Google Cloud console, without needing to trigger from FlutterFlow Studio. This is especially useful for debugging purposes. For step-by-step instructions, including an example and how to structure the request, refer to the Testing Cloud Functions in Google Cloud Console section.

Update App Badge Count (iOS only) [Action]

The Update App Badge Count action lets you manually display a numeric badge on your iOS app icon. This badge typically indicates pending tasks or updates, such as unread messages, notifications, or reminders.

badge-count

To implement, simply enter the number of Badge Count the app should display on the home screen icon.

set-app-badge-count-ios

FAQs

Push notifications not working; Getting cloud function error: PERMISSION_DENIED: Missing or insufficient permissions

If you encounter an error with push notifications, specifically a cloud function failure due to permission issues, it might be related to your Google Cloud organization’s settings. Organizations can disable automatic IAM grants for default service accounts, leading to this error.

To fix this issue, manually grant the Editor role to the default service account used by your project. You can do this by visiting the GCP IAM page and assigning the Editor role to the following service account:

  • For App Engine (Gen 1): {firebase-project-id}@appspot.gserviceaccount.com
  • For Compute Engine (Gen 2): {project-number}-compute@developer.gserviceaccount.com

pn-faq-img-1

Also, ensure that these principals (emails) and their roles are present in the permissions tabs in App Engine Default service account, Default compute service account, and firebase-adminsdk. You can do this by visiting the GCP Service Accounts page, clicking on each service account email, and granting access to these principals in the permissions tab.

Below is a sample image for App Engine Default service account. pn-faq-img-2

Last updated on