Cordova

📲 Handling FCM Token Registration in Cordova

🔧 Integration with phonegap-plugin-push

The following steps and code snippets guide you through retrieving the FCM device token in a Cordova app and passing it to the REL-ID SDK.


🛠️ Plugin Installation

Install the plugin required for push notifications:

cordova plugin add phonegap-plugin-push

📁 Android Configuration

  1. Download google-services.json from the Firebase Console.
  2. Copy it to the platforms/android/app/ directory.
  3. Add the following to your config.xml:
<platform name="android">
  <resource-file src="platforms/android/app/google-services.json" target="google-services.json" />
</platform>

🍎 iOS Configuration

  1. Enable the following capabilities in Xcode:
    • Push Notifications
    • Background Modes → Remote notifications
  2. From <platforms/ios> run:
pod install

🔄 Device Token Retrieval & SDK Integration

Place the following code in your onDeviceReady method to capture and forward the FCM token to the REL-ID SDK:
This code snippet demonstrates how to initialize push notifications in a Cordova app using the phonegap-plugin-push plugin, retrieve the device token (FCM/APNS), and pass it to the REL-ID SDK for secure push-based authentication and alerts.


// - Register a listener to ensure that the push setup only runs after Cordova's device APIs are ready.
document.addEventListener("deviceready", onDeviceReady, false);

//- Initializes the push notification plugin.
//- Configures iOS-specific options like alert, badge, and sound permissions.
//- The `android: {}` block can be extended for Android-specific options if needed.

function onDeviceReady() {
  const push = PushNotification.init({
    android: {},
    ios: {
      alert: "true",
      badge: "true",
      sound: "true"
    }
  });

// Listens for the `registration` event which is triggered when the device successfully registers with FCM (Android) or APNS (iOS).
// `data.registrationId` contains the **unique device token** used for push delivery. 
  
  push.on('registration', (data) => {
    console.log("FCM Token:", data.registrationId);

// **Passes the device token to the REL-ID SDK** using `setDeviceToken`.
// This is essential for REL-ID to deliver push notifications to this device for verification, login, or approval workflows.
// `updateSuccess` and `updateFailure` are callback handlers for success or failure of this registration with the SDK.  
    
    com.uniken.rdnaplugin.RdnaClient.setDeviceToken(
      this.updateSuccess,
      this.updateFailure,
      [data.registrationId]
    );
  });

  // Handle plugin errors
  push.on('error', (error) => {
    console.error('Push plugin error:', error);
  });
}

✅ Summary

This setup ensures that:

  • The device is properly registered with FCM/APNS.
  • The token is passed to the REL-ID SDK so it can use the push channel for secure notification flows.
  • Errors are logged for debugging and troubleshooting.

🧠 Notes

  • This token is required by the REL-ID SDK for push notification delivery.
  • Make sure to save or transmit the token to your server if needed.
  • The registration event is fired when the token is initially generated or refreshed.

📤 Next Steps

  • Ensure your Firebase project is correctly set up.
  • Handle notification display and navigation based on your app's login state.
  • Securely handle and store device tokens if used outside the SDK context.