Jos*_*ebi 6 android react-native expo expo-notifications
我在项目中使用 expo React Native,并且在项目中使用 expo-notifications 包。
我已将 "useNextNotificationsApi": true 添加到 android 对象下的 app.json 文件中,该文件位于 expo 对象下,因此 expo.android.useNextNotificationsApi : true。
我还在从服务器发送到 expo 服务器的消息上设置了 experienceId,我使用https://github.com/expo/expo-server-sdk-node包进行发送。
messages.push({
to: red_user.fcm_token,
sound: 'default',
title: "Stylist Response",
body: "Stylist has agreed to fulfill the request",
data: {
experienceId: "@glamcentralng/GlamCentral",
order: order._id,
stylist_response: "agreed"
},
})
Run Code Online (Sandbox Code Playgroud)
在我的 expo React Native 应用程序中,我正在使用我提到的 expo-notifications 包,并且我的类组件中有以下设置。
import * as Notifications from 'expo-notifications';
.
.
.
.
componentDidMount() {
//Not working at all
Notifications.addNotificationReceivedListener( notification => {
console.log(notification);
this._handleNotification(notification)
});
//Working well
Notifications.addNotificationResponseReceivedListener(response => {
console.log(response);
});
this.registerForPushNotificationsAsyncNew();
}
Run Code Online (Sandbox Code Playgroud)
addNotificationReceivedListener 在收到通知时不会收到通知,但我将其视为我的真实 Android 设备上的正常通知(我没有使用模拟器)。根据文档,当我单击通知时,addNotificationResponseReceivedListener 应该处理它并且确实如此。所以 addNotificationReceivedListener 不起作用,但 addNotificationResponseReceivedListener 效果很好。
还要补充的一件事是,我在按照文档进行注册的函数中获得了一个令牌。
不知道如何解决这个问题,因为我已经检查了这里和 github 上的其他线程。任何帮助表示赞赏。
| 归档时间: |
|
| 查看次数: |
1812 次 |
| 最近记录: |