Push notifications in Yandex Cloud Notification Service
Push notifications are pop-up messages on your smartphone screen with information about Yandex Cloud Notification Service events, its services, promotions, news, and updates.
Push notifications are sent via mobile platform notification services:
- Apple Push Notification service
(APNs). - Firebase Cloud Messaging
(FCM). - Huawei Mobile Services
(HMS).
Push notifications via RuStore
Note
The service is subject to limitations. For more information, see Yandex Cloud Notification Service quotas and limits.
Push notification delivery algorithm using FCM as an example:
- In CNS, you create a mobile push notification channel for a specific platform (FCM) and your app.
- FCM maintains a persistent network connection with all registered mobile devices to deliver push notifications to apps on those devices.
- Your app on a particular device registers in FCM and receives a unique token to send push notifications to that device.
- The token is stored in CNS as a parameter of the application's mobile endpoint.
- To send a notification, you publish a message in CNS and specify the endpoint ID (ARN) as the recipient.
Mobile push notification channel
Minimum list of source data to create a mobile push notification channel:
You can authenticate with APNs using either a token or a certificate:
-
To authenticate using a token, you will need the following data:
-
Signature key: File with the signature key that you will use to certify the authentication token.
Create and download a signature key in your Apple developer account: Certificates, Identifiers & Profiles → Keys →
. You can download the key file only once. -
Key ID (Key ID): Get the ID in your Apple developer account: Certificates, Identifiers & Profiles → Keys. Make sure the ID matches the signature key you downloaded in the previous step. It must be 10 characters long.
-
Developer ID (Team ID): You can find it in the top-right corner of your Apple developer account. It must be 10 characters long and contain only numbers and Latin letters.
-
Bundle ID: Get the bundle ID
in your Apple developer account: Certificates, Identifiers & Profiles → Identifiers or in the Xcode app: Target → General → Identity. It may contain only numbers, Latin letters, hyphens, and periods.
Learn more about the token in the relevant Apple documentation
. -
-
To authenticate using a certificate, you will need the following data:
- Certificate: SSL certificate file in
.pem
format. - Private certificate key: Key file in
.pem
format.
For more information about the certificate, see the Apple documentation
.To save the certificate and the private key in individual
.pem
files, use the openssl Linux utility:openssl pkcs12 -in Certificates.p12 -nokeys -nodes -out certificate.pem openssl pkcs12 -in Certificates.p12 -nocerts -nodes -out privatekey.pem
- Certificate: SSL certificate file in
Token-based authentication is preferred as a faster, more modern and secure option.
The notification channel name must be unique within the cloud. For APNs channels, we recommend specifying the bundle ID in the name.
You can authenticate with FCM using either the HTTP v1 API or Legacy API:
- To authenticate using the HTTP v1 API, you will need a Google Cloud service account key in JSON format. The key is used to generate OAuth 2.0 temporary tokens for authenticating requests in the FCM HTTP v1 API. You can get it in the Google Cloud management console.
- To authenticate using the Legacy API, you will need an API key (server key). You can get it in the Firebase management console.
Note
The HTTP v1 API is preferred as FCM will no longer support
See more in the Firebase documentation
The notification channel name must be unique within the cloud. For FCM channels, we recommend specifying the full package name.
You can authenticate with HMS using the following parameters:
- Key ID
- API key
See more in the HMS documentation
The channel name must be unique within the cloud. For HMS channels, we recommend specifying the full package name.
Once you create a notification channel, it gets a unique ID (ARN).
Mobile endpoints
Each channel has its own base of mobile endpoints to send notifications directly to the app on user devices.
A mobile endpoint contains information about a token to send push notifications to a specific device and notification channel ID (ARN).
Token lifetime
Push notification tokens have a limited lifetime that depends on a specific platform, user actions, and other factors.
CNS gets feedback from each platform when sending notifications and uses it to manage tokens. If the token has changed, CNS will write a new token to the endpoint, or delete the endpoint if the token is out of date.
Recommended algorithm for working with tokens using a mobile app:
- The app registers in the mobile notification service, e.g., APNs, and receives a token to send push notifications.
- The app provides the token to CNS, gets the endpoint ID (ARN), and stores it on the device.
- Each time the app is launched, it registers again in the mobile notification service, e.g., APNs, and checks to see if the token has changed.
- If the token has changed, the app provides the new token and the endpoint ID (ARN) to CNS. If such an endpoint ID (ARN) does not already exist for some reason, a new endpoint is created in CNS and stored in the app.
Tip
We do not recommend overwriting the token in the endpoint each time the app is launched. If the token has not changed, in some cases this may result in lost notifications.