我遇到了一个与这个问题极其相似的问题。
- I am using Expo (SDK38) with the Managed Workflow
- I am creating standalone APK builds with Turtle CLI on CI
- I have an FCM project working almost perfectly with the standalone app. By almost perfectly I mean:
- That I am successfully obtaining the device FCM token with the following code:
import { Notifications } from 'expo'; await Notifications.getDevicePushTokenAsync(); // Gives the token successfully
- That I am sending a push notification when running the following NodeJS script, but:
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' });
- [Minor issue 1] The device does not show any notification if the app is in foreground;
- [Minor issue 2] The device shows the notification duplicated if the app is not in foreground.
- That I am successfully obtaining the device FCM token with the following code:
我尝试过旧版通知模块和新版通知模块:
// 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,
}),
});
请注意,与我在上面链接的类似问题中一样,我不使用Expo通知令牌(格式为
ExponentPushToken[xxxxxx]
)。我使用通过Notifications.getDevicePushTokenAsync()
获取的标准FCM令牌。请问如何使其正常工作?