Push Notifications
Learn how to send push notifications to users when they are offline.
Push Notifications provide a way to deliver some information to a user while they are not using your app actively. The following use cases can be covered by push notifications:
- Offline messages. Send a chat message when a recipient is offline. In this case, a push notification will be sent automatically if the user is offline.
- Offline calls. Make a video/audio call with offline opponents. In this case, a push notification will be sent manually.
- Requests to contact list. Send requests to add a user to the contact list. In this case, a push notification will be sent manually).
- User tags. Send notifications to specific user groups defined by tags.
Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out our Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
Configuration
In order to start working with push notifications, you need to configure it.
- For iOS application that uses Apple Push Notifications, you must have APNS certificate uploaded via the QuickBlox Dashboard Console panel. Review this page for more details.
- For Android application that uses Firebase Cloud Messaging (FCM) you need to obtain API Key and set it on QuickBlox Dashboard Console panel. Review this page for more details.
Send push notifications
You can manually initiate sending push notifications to user/users on any event in your application. To do so, you need to form push notification parameters (payload) and set the push recipients.
var payload = JSON.stringify({
message: "New market products are available",
ios_voip: "1",
VOIPCall: "1"
});
var pushParameters = {
notification_type: "push",
user: { ids: [21, 12] }, // recipients.
environment: "development", // environment, can be 'production'.
message: QB.pushnotifications.base64Encode(payload)
};
QB.pushnotifications.events.create(pushParameters, function(error, result) {
if (error) {
console.log(error);
} else {
// success
console.log("Push Notification is sent.");
}
});
You can send only FCM data messages to the Android app. QuickBlox doesn't support FCM notification messages.
To process FCM data messages on your app when the app is in the background, you need to handle them. If not handled, they will not pop on the screen even if the app has received such push notification. See FCM documentation to learn more about data messages.
You can send APNS VoIP notifications from the web app to the iOS app. However, if the IOS app is not subscribed to APNS VoIP notifications or the APNS VoIP certificate has expired, the regular APNS will be delivered instead of APNS VoIP.
Updated about 3 years ago