Expo 应用程序打开,然后在关闭应用程序并单击通知时崩溃 [android]

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

当应用程序关闭/未运行并单击通知时,我的 React Native Expo android 应用程序总是崩溃。

它打开显示启动画面,然后在几秒钟后崩溃

如果点击通知时应用程序已经打开,它工作正常。

这是一个生产版本,它没有报告或显示任何错误(Bugsnag 没有显示任何错误)。

请问我该如何解决?

*有人建议我用 logcat 检查错误,但我不知道错误在 React Native 中意味着什么或如何修复它

Error logcat detected

你的贡献将不胜感激。

之前,我认为这是因为我的应用程序导航器的排列方式。

我有三个领航员,

  1. InitNavigator - 只包含闪屏
  2. AuthNavigator - 身份验证屏幕
  3. AppNavigator - 包含用户在成功登录时看到的屏幕

我的第一个实现是 appNavigator 仅在用户登录时有条件地挂载。 该应用程序在 asyncStorage 中看到 JWT 时就知道用户已登录。

所以我必须在启动应用程序时先从 asyncStorage 获取信息

但在遇到这个问题后,我确保在应用程序加载时安装了所有导航器

<AppStack.Navigator
      screenOptions={{ headerShown: false }}
      // initialRouteName={routes.APP_NAVIGATOR.SINGLE_POST}
    >
      {/* Initial/Splash Screen */}
      <AppStack.Group>
        <AppStack.Screen name="splashScreen" component={SplashScreen} />
      </AppStack.Group>
      {/* Authentication Screen */}
      <AppStack.Group>
        <AppStack.Screen
          name={routes.AUTH_STACK_NAVIGATOR.SIGNUP_NAVIGATOR}
          component={UserProvider}
        />
      </AppStack.Group>
      <AppStack.Group>
        {/* <AppStack.Screen name="demo" component={ViewCommunityProfile} /> */}
        <AppStack.Screen
          name={routes.APP_NAVIGATOR.COMMUNITY_NAVIGATOR}
          component={SideDrawer}
        />

        <AppStack.Screen
          name={routes.APP_NAVIGATOR.SET_LOCATION}
          component={Location}
        />

        <AppStack.Screen
          name="EditCommunityProfile"
          component={EditCommunityProfile}
        />
        <AppStack.Screen
          name={routes.APP_NAVIGATOR.CREATE_POST_NAVIGATOR}
          component={CreatePostNavigator}
        />
        <AppStack.Screen
          name={routes.APP_NAVIGATOR.PROFILE_NAVIGATOR}
          component={ProfileNavigator}
        />
        <AppStack.Screen
          name={routes.APP_NAVIGATOR.CHAT_NAVIGATOR}
          component={ChatNavigator}
        />
        <AppStack.Screen
          name={routes.APP_NAVIGATOR.SINGLE_POST}
          component={SinglePost}
        />
      </AppStack.Group>
    </AppStack.Navigator>

这是处理通知的代码

  • 通知在包装整个应用程序的上下文中处理
responseListener.current =
      Notifications.addNotificationResponseReceivedListener((response) => {
        const notificatonContent = response.notification.request.content;
        if (notificatonContent.data?.url) {
          openUsingDefaultUrl(notificatonContent.data.url);
        } else {
          openUsingDefaultUrl("/notification");
        }
      });

我还添加了代码来处理应用程序在后台时点击的通知

import * as TaskManager from "expo-task-manager";

const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";

TaskManager.defineTask(
  BACKGROUND_NOTIFICATION_TASK,
  ({ data, error, executionInfo }) => {
    if (error) {
      Bugsnag.notify(error);
    }
    if (data) {
      if (data?.url) {
        openUsingDefaultUrl(data.url);
      } else {
        openUsingDefaultUrl("/notification");
      }
    }
  }
);
android react-native expo react-native-navigation expo-notifications
© www.soinside.com 2019 - 2024. All rights reserved.