logo

subscribeToFCM

The subscribeToFCM function subscribes to Firebase Cloud Messaging using a deprecated API. Exists only for retro compatibility reasons, please use the registerToFCM function instead. Optionally registers with already existing ACG ID and ACG security token.

  • The app ID is the package name of the app.
  • The ECE auth secret and ECE public key must be generated beforehand with the createFcmECDH and generateFcmAuthSecret functions. The auth secret and ECDH keys must be stored.

Returns the ACG ID, ACG security token and FCM token, which must be stored.

This function uses a deprecated API and will stop working in June 2024.

import { subscribeToFCM } from '@aracna/fcm';

const authSecret = generateFcmAuthSecret();
const ecdh = createFcmECDH();

subscribeToFCM({
  appID: 'YOUR_APP_ID',
  ece: {
    authSecret: authSecret,
    publicKey: ecdh.getPublicKey()
  },
  senderID: 'YOUR_SENDER_ID'
})
  .catch(() => {})
  .then((subscription) => {
    // will log { acg: { id: bigint, securityToken: bigint }, token: string }
    console.log(subscription);
  });