When your app is disconnected from Stringee Server, it cannot receive real-time updates. Use Stringee Push Notification to keep the app informed about new chat events.
Configure Firebase Cloud Messaging for Android. For iOS, create an iOS push project on Stringee Dashboard and upload an APNs authentication key as described in iOS Push Notification.
You can use FlutterFire to obtain the token. On Android, register the FCM token:
String? pushToken = await FirebaseMessaging.instance.getToken();
On iOS, request notification permission first, then obtain the APNs token:
await FirebaseMessaging.instance.requestPermission();
String? pushToken = await FirebaseMessaging.instance.getAPNSToken();
The APNs token can be unavailable immediately after startup. Retry after APNs registration completes and listen to token refresh events so the new token can be registered.
Register the token after StringeeClient has connected:
if (pushToken != null && pushToken.isNotEmpty) {
final result = await client.registerPush(
pushToken,
isProduction: false,
isVoip: false,
);
print("Register push: ${result['message']}");
}
On Android, isProduction and isVoip are ignored. On iOS, use isVoip: false for chat notifications and set isProduction to match the APNs environment used by your app.
When the token changes, register the new value again:
FirebaseMessaging.instance.onTokenRefresh.listen((token) {
client.registerPush(token, isProduction: false, isVoip: false);
});
Stringee chat notifications contain a data payload similar to:
{
"stringeePushNotification": "1.0",
"type": "CHAT_EVENT",
"data": {
"convId": "CONVERSATION_ID",
"convName": "Conversation name",
"from": "USER_ID",
"displayName": "Display name",
"msgId": "MESSAGE_ID",
"seq": 2,
"type": 1,
"message": {
"content": "Hello"
}
}
}
When the user signs out, unregister the token before disconnecting:
if (pushToken != null && pushToken.isNotEmpty) {
await client.unregisterPush(pushToken);
}
You can view the Flutter chat notification sample on GitHub: chat_notification_sample