React Native 后台 Websockets/MQTT

问题描述 投票:0回答:2

当应用程序在后台运行或使用本机关闭应用程序时,显示从 mqtt/websockets 接收的消息通知的正确方法是什么。

到目前为止,我已经实现了当应用程序位于前台时显示通知,使用 react-native-paho-mqtt 作为 mqtt 客户端,并使用 react-native-push-notification 显示通知

android react-native websocket push-notification mqtt
2个回答
0
投票

如果应用程序在前台运行,则将从套接字收到的消息显示为“Snackbar”或“Toast”或其他方式。 如果应用程序在后台运行,则从套接字收到的消息应显示为应用程序的push-notification


0
投票

当应用程序处于后台状态时,您仍然可以接收消息,并且您需要在 Android 中创建一个前台服务,以保持 Mqtt 连接处于活动状态,以便即使在应用程序被终止后也能接收消息。

对于通知,请使用 React Native Notifee。

© www.soinside.com 2019 - 2024. All rights reserved.