Send Things5 event notifications to browsers and native mobile apps through Firebase Cloud Messaging
Things5 can send push notifications to the user's browsers and to native mobile apps (iOS and Android) when a device raises an event the user has subscribed to. Delivery goes through Firebase Cloud Messaging (FCM): your app gets a token from Firebase and registers it with Things5, and Things5 sends the notifications to every registered device of the user.
How it works
- The user chooses which events of a device model they want to be notified about (see Event notifications).
- Your app gets an FCM registration token from the Firebase SDK and registers it with Register push device.
- When a device raises one of those events, Things5 sends a push notification to the user's registered devices on the platforms the user has enabled.
Firebase setup
Tokens are tied to the Firebase project that generated them, so your app must be configured with the Things5 Firebase project: tokens from any other project are rejected by FCM. Contact Things5 to register your app (Android package name, iOS bundle ID) and to get its google-services.json / GoogleService-Info.plist.
iOS
Use the Firebase Messaging SDK and register the FCM token it returns, not the raw APNs device token. Push delivery to iOS also needs your app's APNs authentication key (.p8) to be uploaded to the Firebase project: send it to Things5 together with your bundle ID.
Getting the token
| Platform | Steps |
|---|---|
| Android | Ask for the POST_NOTIFICATIONS permission (Android 13+), then read FirebaseMessaging.getInstance().token. FirebaseMessagingService.onNewToken() is called when the token changes. |
| iOS | Ask for permission with UNUserNotificationCenter.requestAuthorization, call registerForRemoteNotifications(), then read Messaging.messaging().token or implement messaging(_:didReceiveRegistrationToken:). |
| Flutter / React Native | getToken() and onTokenRefresh from firebase_messaging / @react-native-firebase/messaging. |
Token lifecycle
| When | Call |
|---|---|
| App start or login | Register push device with platform and user_agent. You can use Check push device first. |
| Firebase rotates the token | Register the new token and unregister the old one. |
| User logs out | Unregister push device, then delete the token in the Firebase SDK so the next user on the same device gets a new one. |
| User manages their devices | List push devices and Update push device to rename a device or turn it off. |
The token goes in the URL path: URL-encode it, since it may contain :.
Who receives a notification
A device receives a notification when all of these hold:
- the user is subscribed to that event for the device model (Event notifications);
- the channel for the device's platform is enabled on the user:
web_notifications_enabledforwebdevices,mobile_notifications_enabledforiosandandroiddevices (see Current user update); - the device itself is
enabled(Update push device).
Notification content
The notification title and body are already translated into the user's language. The data payload carries:
| Key | Description |
|---|---|
machine_id | ID of the device that raised the event. Use it to open the device screen when the user taps the notification. |
machine_name | Name of the device |
event_name | Name of the event, translated into the user's language |
