【发布时间】:2020-12-14 12:42:34
【问题描述】:
我面临一个与this one 极为相似的问题。
- 我正在将 Expo (SDK38) 与托管工作流一起使用
- 我正在使用 Turtle CLI on CI 创建独立的 APK 版本
- 我有一个 FCM 项目几乎可以与独立应用程序完美配合。 几乎完美我的意思是:
- 我使用以下代码成功获取了设备 FCM 令牌:
import { Notifications } from 'expo'; await Notifications.getDevicePushTokenAsync(); // Gives the token successfully - 运行以下 NodeJS 脚本时,我正在发送推送通知,但是:
const admin = require('firebase-admin'); admin.initializeApp({ credential: require('./my-credentials.json'), databaseURL: 'https://MY_URL_HERE' }); admin.messaging.send({ notification: { title: 'Foo', body: 'Bar' }, android: { ttl: 86400 }, token: 'THE_FCM_TOKEN_HERE' });- [小问题 1] 如果应用在前台,设备不会显示任何通知;
- [小问题 2] 如果应用不在前台,设备会显示重复的通知。
- 我使用以下代码成功获取了设备 FCM 令牌:
为了完整性,我已经提到了上面的小问题,但我现在面临的主要问题是我的应用程序只是不会注意到通知到达。侦听器不会触发。
Legacy Notifications Module 和New Notifications Module 我都试过了:
// Attempt using Legacy Notifications
// https://docs.expo.io/versions/v38.0.0/sdk/legacy-notifications/
import { Notifications as LegacyNotificationsModule } from 'expo';
// Attempt using New Notifications Module
// https://docs.expo.io/versions/v38.0.0/sdk/notifications/
import * as NewNotificationsModule from 'expo-notifications';
LegacyNotificationsModule.addListener(() => {
// Make any UI change just for we to see it happening
});
NewNotificationsModule.addNotificationReceivedListener(() => {
// Make any UI change just for we to see it happening
});
// I also tried commenting and uncommenting the code below
NewNotificationsModule.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
回想一下,就像在 the similar issue I linked above 中一样,我不使用 Expo 通知令牌(形式为 ExponentPushToken[xxxxxx])。我正在使用通过Notifications.getDevicePushTokenAsync() 获得的标准 FCM 令牌。
我怎样才能做到这一点?
【问题讨论】:
标签: android react-native push-notification firebase-cloud-messaging expo