小编Ste*_*lla的帖子

消息()。onNotificationOpenedApp 永远不会被触发,消息()。getInitialNotification()被触发但remoteMessage 总是为空

我正在使用 react-native-firebase v6.4.0。我成功注册了一个后台处理程序,setBackgroundMessageHandler一切正常。现在我正在尝试在应用程序处于后台/退出时处理通知点击并且我正在使用onNotificationOpenedApp/ getInitialNotification。我面临的问题是第一种方法永远不会被触发,而第二种方法被触发,但remoteMessage参数总是null. 我也试过生成一个发布版本,但结果是一样的。

索引.js

// imports

messaging().setBackgroundMessageHandler(async remoteMessage => {
  // storing the message with redux
});

function HeadlessCheck({isHeadless}) {
  return isHeadless ? null : <App />;
}

AppRegistry.registerComponent(appName, () => HeadlessCheck);

Run Code Online (Sandbox Code Playgroud)

应用程序.js

// other imports
import messaging from '@react-native-firebase/messaging';
import {store, persistor} from './Store';

export default function App() {
  useEffect(() => {
    (async () => await messaging().registerDeviceForRemoteMessages())();

    const unsubscribe = messaging().onMessage(async remoteMessage => {
      store.dispatch(storeNews(remoteMessage));
    });

    messaging().onNotificationOpenedApp(remoteMessage => …
Run Code Online (Sandbox Code Playgroud)

messaging android background react-native react-native-firebase

6
推荐指数
1
解决办法
3281
查看次数

通过 websocket 响应原生 STOMP

我正在尝试通过 websocket 和 STOMP 协议构建一个 React Native 消息传递应用程序(对于服务器端,我使用的是 Spring Boot),但我得到了一个非常奇怪的行为。我的代码如下:

...
import SockJS from 'sockjs-client'; // Note this line
import Stomp from 'stompjs';

function ChatScreen() {
   // Variables declaration

   useEffect(() => {
    const socket = new SockJS('http://localhost:8080/chat');
    const stompClient = Stomp.over(socket);
    const headers = {Authorization: `Bearer ${jwt}`};

    stompClient.connect(headers, () => {
      stompClient.subscribe(
        `/user/${user.username}/queue/messages`, console.log, headers,
      );
    });

    return () => stompClient && stompClient.disconnect();
  }, [jwt, user.username]);

  ...
}
Run Code Online (Sandbox Code Playgroud)

安装上述组件后,我得到:

哎呀!与http://localhost:8080/chat 的连接丢失

然后,如果我将 SockJS 导入行从 更改import SockJS from …

android stomp websocket sockjs react-native

5
推荐指数
1
解决办法
4725
查看次数