创建SNS端点设备令牌错误[Expo]



创建应用程序端点时,不接受设备令牌。Exo返回类似ExponentPushToken[91hX**********]的令牌

在下面的表格中写着:

最多400个字符。只允许使用十六进制字符ara

我将令牌转换为十六进制,它仍然不接受设备令牌。

为了在expo中获得设备令牌,我遵循expo通知指南。

async function registerForPushNotificationsAsync() {
let token;
if (Device.isDevice) {
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
return token;
}

根据https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-application-as-subscriber.html#sns-用户通知的工作方式,SNS没有将Expo列为支持的平台。

虽然Expo支持iOS和FCM,SNS也支持这两个平台,但SNS不支持Expo在这些平台上添加的附加层。

如果您不直接使用Expo通知服务,则需要使用getDevicePushTokenAsync()而不是getExpoPushTokenAsync()

最新更新