当应用程序关闭/未运行并单击通知时,我的 React Native Expo android 应用程序总是崩溃。
它打开显示启动画面,然后在几秒钟后崩溃
如果点击通知时应用程序已经打开,它工作正常。
这是一个生产版本,它没有报告或显示任何错误(Bugsnag 没有显示任何错误)。
请问我该如何解决?
*有人建议我用 logcat 检查错误,但我不知道错误在 React Native 中意味着什么或如何修复它
你的贡献将不胜感激。
之前,我认为这是因为我的应用程序导航器的排列方式。
我有三个领航员,
我的第一个实现是 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");
}
}
}
);