【问题标题】:expo-notifications - Error encountered while updating the device push token with the serverexpo-notifications - 使用服务器更新设备推送令牌时遇到错误
【发布时间】:2021-08-03 16:54:36
【问题描述】:

我正在为我的 react-native 项目使用 Expo 的裸工作流。我正在使用世博会的推送通知服务。每当我尝试获取我的 expo 推送令牌时,我都会收到以下错误:

[expo-notifications] Error encountered while updating the device push token with the server: {"error":"invalid_token","error_description":"The bearer token is invalid"}

我直接在我的设备上运行应用程序,所以应该能够收到通知。

我使用的registerForPushNotificationsAsync()documentation 中提供的基本相同。

import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import { Platform } from 'react-native';

export const registerForPushNotificationsAsync = async () => {
  try {
    if (Constants.isDevice) {
      const experienceId = '@{username}/{slug}';

      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;
      }
      const token = (
        await Notifications.getExpoPushTokenAsync({ experienceId })
      ).data;
      console.log('  ????  ????   Token :', token);
      return 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 undefined;
  } catch (error) {
    console.error('Error in registerForPushNotificationsAsync()', error);
    return undefined;
  }
};

在 package.json 中展示包

    "expo": "~40.0.0",
    "expo-analytics": "^1.0.16",
    "expo-app-loading": "^1.0.1",
    "expo-font": "~8.4.0",
    "expo-image-manipulator": "~8.4.0",
    "expo-image-picker": "~9.2.0",
    "expo-intent-launcher": "~8.4.0",
    "expo-notifications": "~0.8.2",
    "expo-splash-screen": "~0.8.0",
    "expo-updates": "~0.4.0",

我看不到任何关于设置不记名令牌的信息,所以我不确定它可能在什么之后,甚至在哪里设置它,假设我能够确定它之后是什么不记名令牌。

有谁知道是什么原因造成的?

【问题讨论】:

    标签: ios react-native push-notification expo


    【解决方案1】:

    所以我们想通了。

    我们使用 fetch-token-intercept 将我们的不记名令牌添加到前往 expo 的调用中,这意味着验证失败。

    我们修改了函数以排除对 expo 的调用,使其不包含我们的不记名令牌,现在令牌已成功检索。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-30
      • 2011-11-20
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多