Natively Docs
Join our community 🔥
  • 👩‍🚀Getting Started
    • What is Natively?
    • Why Natively?
    • FAQ
    • Create Your First App
  • 🚀Natively Platform
    • 🚉Releases
    • 🖌️Appearance
      • 😼App Icon
      • 📱Loading Screen
      • 📱Error Screen
      • 🎨Style
    • 🎬Preview
    • ⭐Features
      • 🛳️Bottom Bar
      • 🚇Deeplinks
        • 🔥Firebase
        • 🔗Universal Links
        • 🌱Branch.io
      • 📍Geolocation
      • 🔔Notifications
        • 📲OneSignal Notifications
        • 🔥Firebase Notifications (Advanced)
      • 📒Contacts
      • 👩‍🎨Social Auth
        • 🍏Sign In with Apple
      • 💟HealthKit
      • 💰Purchases
      • 🤑Admob
      • 💳NFC
      • 📷Camera
      • 📂Photo Library
      • 🎤Microphone
      • 📈Analytics
        • 🕊️AppsFlyer
        • 😛Facebook
    • 🚚Publish
      • 🍏iOS App
      • 🤖Android App
    • ⚙️Settings
    • 🙈Subscription Plans
  • Guides
    • 🧋Integration (Native Features)
      • 🏅How to get started?
      • ℹ️Device
      • ℹ️Browser Info
      • 🛳️Bottom Bar
      • ✂️Clipboard
      • 🚦Push Notifications - OneSignal
      • 🚦Push Notifications - Firebase (Advanced)
      • 📍Geolocation
      • 📦App Storage
      • 🗝️Biometrics & Credentials
      • 📧Native SMS/Email
      • 📅Native Date Picker
      • 📸Native Camera
      • 🎙️Native Audio Recorder
      • 🈁Native Scanner (QR/Barcode)
      • 📔Contacts
      • 🍏Apple Sign In
      • ❤️HealthKit
      • 💸In-App Purchases
      • 🤑Admob
      • 💳NFC
      • 🥑Show Toast/Banner
      • ⏳Show/Hide Loading Screen
      • 🥑Haptic Feedback
      • 🖼️Share Media/Files
      • 📱Open an external App/URL
      • ✍️Request User's review
      • ↔️getInsets
      • 🎨Control Style & Colors
    • 🔍Troubleshooting
    • 🐈Setup RevenueCat App
    • 🚑Setup Admob App
    • 🚥Setup One Signal App
    • 🧑‍🤝‍🧑Setup website Universal Links (Deeplinks)
    • 🍕Testing & Submitting your app
    • 🔑Generate iOS Push Key (NEW)
    • 🔑Generate iOS Push Certificate (Legacy)
    • 🤝Affiliate program
    • 📕For Partners: Natively Brand Book.
Powered by GitBook
On this page
  • 🧋 Bubble.io Plugin
  • Bubble - Setup example
  • 🛠 JavaScript SDK
  • Recommendations

Was this helpful?

  1. Guides
  2. Integration (Native Features)

Push Notifications - Firebase (Advanced)

PreviousPush Notifications - OneSignalNextGeolocation

Last updated 5 months ago

Was this helpful?

We are using Service to provide a Push Notification functionality.

🧋 Bubble.io Plugin

[Element] Natively - Push Notifications (Firebase)

Initialization:

On initialization, the element will try to get the current notification permission status. (No need to call it on the Page Is Load event)

Element Events:

  • Firebase FMC Token Updated - get called when was updated.

  • Firebase APNS Token Updated - get called when was updated.

  • Notification permissions authorized - get called when the user clicks Allow on permission alert.

  • Notification permissions denied - get called when the user clicks Decline on permission alert.

  • Notification permissions status updated - get called when permission status was updated because of the user's action.

  • Topic subscription status - get called when topic subscription status was updated because of the user's action: subscribe/unsubscribe.

Element States:

  • Permission Status - Yes or No.

  • Topic subscription status - 'SUCCESS' if the 'subscribe' action was successful

  • Topic unsubscribe status - 'SUCCESS' if the 'unsubscribe' action was successful

You will need the FMC token value to send a push notification. Take this value on the user's login and store it in a database. (For example, you can add a property to the user named fmc_token)

You will need the APNS token value to send a push notification to iOS device. Take this value on the user's login and store it in a database. (For example, you can add a property to the user named apns_token)

Element Actions:

  • Request the user's push notification permission - displays a systems popup with your Notification Permissions Text

  • Get the user's Firebase APNS Token - Reload the user's Firebase APNS token

  • Get the user's Firebase FCM Token - Reload the user's Firebase FCM token

  • Get the user's push notification permission status

  • Subscribe to topic

  • Unsubscribe from topic

How to send Push Notifications with Firebase?

  1. Cloud Messaging REST API

To a topic subscribers

curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send \
-d '{
"message": {
"notification": {
"title": "Notification to All App Users",
"body": "This is for all users of the app."
},
"data": {
"url": "{YOUR_URL_TO_OPEN_INSIDE_OF_THE_APP}",
},
"topic": "all"
}
}'

To a single user

curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send \
-d '{
"message": {
"notification": {
"title": "Notification to a Single App Users",
"body": "This is for a single user of the app."
},
"data": {
"url": "{YOUR_URL_TO_OPEN_INSIDE_OF_THE_APP}",
},
"token": "{FCM_TOKEN}"
}
}'

Bubble - Setup example

These steps provide a general guide. You can adapt them to fit the specific needs and logic of your application.

  1. Request Push Notification permission whenever you need it.

  2. Save APNS token to your user model (only for iOS)

  3. Save FCM token to your user model

🛠 JavaScript SDK

NativelyNotifications

const notifications = new NativelyFirebaseNotifications()
const apns_token_callback = function (resp) {
        console.log(resp.token); // string
};
const token_callback = function (resp) {
        console.log(resp.token); // string
};
const topic = "FCM topic name" // string
const subscribe_callback = function (resp) {
        console.log(resp.status); // string
        console.log(resp.message); // string. error message if any
};  
const unsubscribe_callback = function (resp) {
        console.log(resp.status); // string
        console.log(resp.message); // string. error message if any
};  
const permission_callback = function (resp) {
        console.log(resp.status); // true/false
};
const permission_status_callback = (instance) => (resp) => {
        console.log(resp.status); // true/false
};
notifications.firebase_get_apns_token(apns_token_callback);
notifications.firebase_get_token(token_callback);
notifications.firebase_subscribe_to_topic(topic, token_callback);
notifications.firebase_unsubscribe_from_topic(topic, unsubscribe_callback);
notifications.firebase_has_permission(permission_status_callback);
notifications.firebase_request_permission(permission_callback);

How to set up?

  1. call firebase_request_permission (required for both iOS & Android).

  2. call firebase_get_apns_token (will return the APNS token for iOS).

  3. call firebase_get_token (will return the FCM token).

  4. Save FMC token and the APNS token (for iOS) somewhere (for example, save them in the user's fcm_token property and apns_token property).

Recommendations

  • Request the user's notification permission. You can do that in any necessary place. For example: show a popup that explains to the user's why your app needs it (so, it can be a better experience when just displaying a system popup)

  • Identify a user by using FCM token.

Firebase FCM Token - 's text value.

Firebase APNS Token - 's text value

Topic ID - the name

Topic ID - the name

Firebase Console -

Topic messaging -

Make sure you've your app and Firebase for Push Notifications.

Check the fcm_token value on each login (It can be )

🧋
🚦
FMC token
APNS token
FCM topic
FCM topic
Firebase Console Docs
Firebase Topic Messaging Docs
prepared
changed
Firebase
FMC token
APNS token
Bubble.io Plugin
JavaScript SDK
Recommendations