Integrating with Other Firebase-Supported Platforms
Because HosteDay's notification system is built on the standard Firebase Cloud Messaging (FCM v1) protocol, you can connect any Firebase-supported platform (Web JavaScript, native Android, native iOS, or React Native) to your HosteDay App.
Standard Integration Flow for Any Platform
Regardless of your frontend language or framework, the integration follows three standard steps:
- Obtain the
FCM Device Token: Use the official Firebase SDK for your platform to request notification permission and retrieve the device token. - Register the Token with HosteDay: Send the token to
POST /api/notifications/devices/registeralong withdevice_idanddevice_type. - Receive & Handle Notifications: Handle incoming foreground/background notifications and read custom
datapayloads (such as deep links).
1. Web Applications (JavaScript / Web)
- Add
firebase-messaging-sw.jsto yourpublic/directory to handle background notifications. - After initializing Firebase Messaging in the browser, retrieve the token and register it with HosteDay:
import { getMessaging, getToken } from 'firebase/messaging';
const messaging = getMessaging(firebaseApp);
const fcmToken = await getToken(messaging, { vapidKey: 'YOUR_VAPID_KEY' });
await fetch('https://my-app.hosteday.com/api/notifications/devices/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Api-Token': 'YOUR_API_TOKEN',
'Authorization': `Bearer ${userToken}`,
},
body: JSON.stringify({
device_token: fcmToken,
device_id: browserDeviceId,
device_type: 'web',
device_name: navigator.userAgent,
}),
});
2. Native Android Apps (Kotlin / Java)
After adding google-services.json and firebase-messaging:
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) return@addOnCompleteListener
val fcmToken = task.result
// Send fcmToken to POST /api/notifications/devices/register
// with device_type = "android"
}
3. Native iOS Apps (Swift)
After adding GoogleService-Info.plist and enabling Push Notifications in Xcode:
Messaging.messaging().token { token, error in
guard let fcmToken = token, error == nil else { return }
// Send fcmToken to POST /api/notifications/devices/register
// with device_type = "ios"
}
4. React Native Apps
Using @react-native-firebase/messaging:
import messaging from '@react-native-firebase/messaging';
import { Platform } from 'react-native';
const fcmToken = await messaging().getToken();
// Send fcmToken to POST /api/notifications/devices/register
// with device_type: Platform.OS === 'ios' ? 'ios' : 'android'
Important Notes for All Platforms
- Token Refresh (
onTokenRefresh): Google periodically refreshes device tokens; always listen for token refresh events and re-send the updated token to/api/notifications/devices/registerusing the samedevice_id. - Unlink on Logout: Call
POST /api/notifications/devices/unregisterwhen a user logs out so another user on the same device does not receive personal notifications. - Allowed
device_typeValues:android,ios,web,macos,windows,linux.