QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms.

Push Notifications

Learn how to send push notifications to users when they are offline.

🚧

This is our documentation for beta version of QuickBlox Flutter SDK. Please contact our Customer Support Team to provide your feedback, suggestions, and requests to improve this page.

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

  1. 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.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  3. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Configuration

iOS

Step1. Create APNS certificate and upload it to the Dashboard.

Each iOS application that uses Apple Push Notifications must have an APNS certificate. Upload the APNS certificate to QuickBlox Dashboard => Push Notifications => Settings => Apple Push Notification Service (APNS). To learn how to create APNS certificates and upload them to Dashboard, refer to our guide.

Step2. Open your project in Xcode and enable Push Notifications capabilities.

  1. Open Xcode and choose your project file.
  2. Choose the Signing & Capabilities tab.
  3. Add a Push Notifications and Background Modes capabilities. To see these sections, you should be logged in to Xcode with your Apple ID that is enrolled in the Apple developer program.
  4. Turn on a Push Notifications capability.
  5. Turn on a Background modes capability. This section requires you to add specific app permissions.
  6. Select a Remote notifications checkbox if you want to receive push notifications when the app goes to background mode.
  7. Select a Voice over IP checkbox if you want your app to receive incoming Voice-over-IP (VoIP) push notifications and use them to display the system call interface to the user when the app is in the background mode.
create apns certificate for your ios app

Android

Step 1. Configure Firebase project and get API key and Sender ID.

First, you should create a Firebase account if you haven't it. Then you should configure your Firebase project. To learn how to configure a Firebase project and get API key and Sender ID, refer to our guide .

Step 2. Add Firebase to your project.

  1. Prepare app dependencies. As part of enabling Firebase services in your Android application, you need to add the google-services plugin to your project android/build.gradle file.
dependencies {
  classpath 'com.google.gms:google-services:4.3.3'
  //...
}

Add Firebase dependency and include gms plugin in the bottom of your module android/app/build.gradle.

implementation "com.google.firebase:firebase-analytics:17.3.0"
//...
apply plugin: 'com.google.gms.google-services'

🚧

Make sure that apply plugin: 'com.google.gms.google-services' is at the end of the file to avoid compilation errors.

  1. Put your google-services.json file for your package into android/app/ folder.

Create push subscription

Subscribe for push notifications. Create a push subscription using the code below.

//Push Channels
//QBPushChannelNames.GCM;
//QBPushChannelNames.APNS;
//QBPushChannelNames.APNS_VOIP;
//QBPushChannelNames.EMAIL;

String deviceToken = "8b75a6c7191285499d890a81df4ee7fe49bc732a";
String pushChannel = QBPushChannelNames.GCM;

try {
  List<QBSubscription?> subscriptions = await QB.subscriptions.create(deviceToken, pushChannel);
} on PlatformException catch (e) {
  // Some error occurred, look at the exception message for more details
}

🚧

A single user can have up to 10 subscriptions on different devices.

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.

//Event Types
//QBNotificationEventTypes.FIXED_DATE;
//QBNotificationEventTypes.PERIOD_DATE;
//QBNotificationEventTypes.ONE_SHOT;

//Notification Event Types
//QBNotificationTypes.PUSH;
//QBNotificationTypes.EMAIL;

//Notification Push Types
//QBNotificationPushTypes.APNS
//QBNotificationPushTypes.APNS_VOIP
//QBNotificationPushTypes.GCM
//QBNotificationPushTypes.MPNS

String eventType = QBNotificationEventTypes.ONE_SHOT;
String notificationEventType = QBNotificationTypes.PUSH;
int pushType = QBNotificationPushTypes.APNS_VOIP;
int senderId = 329873;

Map<String, Object> payload = new Map();
payload["message"] = "test";

try {
  List<QBEvent?> events = await QB.events.create(eventType, notificationEventType, senderId, payload, pushType: pushType);
} on PlatformException catch (e) {
  // Some error occurred, look at the exception message for more details
}

Argument

Required

Description

QBNotificationTypes

yes

Type of notifications:

  • QBNotificationTypes.PUSH - send push notification.
  • QBNotificationTypes.EMAIL - send email.

payload

yes

Push notification payload. Can contain a message (string) property and many other key-value pairs (string-string). Refer here for more details.

recipientsIds

no

Users' IDs to deliver notification.

senderId

yes

ID of the user who created the event.

QBNotificationEventTypes

yes

Types of the notification event.

  • QBNotificationEventTypes.ONE_SHOT - a one-time event (valid only if the date is not specified).
  • QBNotificationEventTypes.FIXED_DATE - a one-time event that occurs at a specified date (valid only if the date is specified).
  • QBNotificationEventTypes.PERIOD_DATE - is a reusable event that occurs within a given period from the initial date (valid only if the period is specified).

name

no

The name of the event. Service information. Only for your own usage.

QBNotificationPushTypes

no

Channel for delivering notification. Used only if the notification type is QBNotificationTypes.PUSH, ignored in other cases.
If a QBNotificationPushTypes is not present, the notification will be delivered to all possible devices/platforms for specified users. Possible values are:
QBNotificationPushTypes.APNS
QBNotificationPushTypes.APNS_VOIP
QBNotificationPushTypes.GCM
QBNotificationPushTypes.MPNS

date

no

The date when the event will be sent on. The date is required if the event type is QBNotificationEventTypes.FIXED_DATE or QBNotificationEventTypes.PERIOD_DATE.
If the type is fixed_date, the date can not be in the past.

endDate

no

The date when the event is completed.
Must be not less than the date value.

period

no

The period of the event in seconds.
The period is required if event's type is QBNotificationEventTypes.PERIOD_DATE.

recipientsTagsAny

no

Recipients (users) must have at least one tag that is specified in the list.

recipientsTagsAll

no

Recipients (users) must have all tags specified in the list.

recipientsTagsExclude

no

Recipients (users) must not have tags specified in the list.

📘

You can send APNS VoIP notifications 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.

Remove push subscription

To delete a subscription, use the following code snippet.

int id = 929988234923;

try {
  await QB.subscriptions.remove(id);
} on PlatformException catch (e) {
  // Some error occurred, look at the exception message for more details
}

Updated 15 days ago


What's Next

Custom Objects

Push Notifications


Learn how to send push notifications to users when they are offline.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.