Back
Tutorials
Mar 19, 2024
How to send iOS critical alerts using FCM
Jobin Jose
Critical Alerts are special type of notifications that bypass the device's DND mode, mute settings to generate an audible notification in emergency situations. It requires special approval from Apple to send critical alerts from your app to your users. In this tutorial, we'll learn how to send critical alerts to iOS apps using FCM (Firebase Cloud Messaging) and APNS.
Prerequisites for sending critical alerts to iOS
Entitled to send critical alerts by Apple (Read more)
Engagespot account (Get one free here)
Google Firebase Cloud Messaging (FCM) configured with APNS (Read more)
1. Activating the FCM provider in the Engagespot console
The first step involves enabling the FCM provider within your Engagespot console. Here's how you can do it.
Navigate to the `Channels -> Mobile Push` section in your Engagespot dashboard.
Activate the FCM provider.
Paste the contents of your Service Account JSON file, which can be procured from your Firebase Settings. Read this guide to learn how to setup FCM with Engagespot.
2. Synchronizing user profiles with FCM tokens
To send push notifications to your users, they must be registered with Engagespot, and their FCM token must be updated in their user profile. The Engagespot API can be used to add FCM tokens to user profiles.
If you're unfamiliar with the Users concept in Engagespot, reading this guide will be helpful.
Here's an example of how to attach FCM token to your user's profile using cURL. (This is usually done directly from your app if you're using our In-App Inbox library, or your backend).
Make sure NOT to use ENGAGESPOT_API_SECRET
in your front-end apps. You should use User token based authentication instead.
Remember to replace YOUR_ENGAGESPOT_API_KEY
, YOUR_ENGAGESPOT_API_SECRET
, and YOUR_FCM_TOKEN with your actual Engagespot API key, secret, and FCM token (obtained from your mobile app) respectively.
3. Dispatching critical alerts via the Engagespot API
You can use our Send Notification REST API or one of our client libraries for Node, PHP, Python etc to trigger notifications from your backend. In the override
parameter, use the fcm
key to pass the custom request payload that needs to be sent to the FCM API.
Since critical alerts is not a native feature supported by Engagespot, we're making use of the override
functionality of our API to send additional payload directly to FCM as per their documentation to send critical alerts.
Here's a Python example:
You can also override any FCM Payload using the `override.fcm` feature. For more details, refer to the [Firebase documentation](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send).
4. Tailoring FCM parameters for critical alerts
The `override.fcm` parameter allows you to customize FCM parameters such as priority and additional payload data. This ensures that critical alerts are delivered promptly and contain relevant information. Here's an example of how to override FCM parameters:
Conclusion
By adhering to these steps and utilizing the provided code examples, you can effectively dispatch critical alerts using FCM in Engagespot. The customization of FCM parameters ensures that your critical notifications are delivered promptly and carry the necessary information. This not only enhances user engagement but also prompts timely action when it's most needed. Leveraging the power of FCM with Engagespot can significantly elevate your user engagement strategy.
Happy coding!