Android Undefined不是对象(正在计算';_PushTokenManager.default.getDevicePushTokenAsync[REACT NATIVE EXPO]

Android Undefined不是对象(正在计算';_PushTokenManager.default.getDevicePushTokenAsync[REACT NATIVE EXPO],android,react-native,push-notification,expo,Android,React Native,Push Notification,Expo,无法使用expo notifications api上的getExpoPushTokenAsync()函数获取令牌。 以下功能与世博会文档完全相同: 从“expo常量”导入常量; 从“世博会通知”导入*作为通知; 从“expo Permissions”导入*作为权限; 异步函数寄存器forpushNotificationsAsync(){ 让代币; if(常量.isDevice){ const{status:existingStatus}=wait Permissions.getAsync(P

无法使用expo notifications api上的getExpoPushTokenAsync()函数获取令牌。 以下功能与世博会文档完全相同:

从“expo常量”导入常量;
从“世博会通知”导入*作为通知;
从“expo Permissions”导入*作为权限;
异步函数寄存器forpushNotificationsAsync(){
让代币;
if(常量.isDevice){
const{status:existingStatus}=wait Permissions.getAsync(Permissions.NOTIFICATIONS);
设finalStatus=existingStatus;
如果(existingStatus!=“已授予”){
const{status}=wait Permissions.askAsync(Permissions.NOTIFICATIONS);
最终状态=状态;
}
如果(最终状态!==‘已授予’){
警报('无法获取推送通知的推送令牌!');
返回;
}
令牌=(wait Notifications.getExpoPushTokenAsync()).data;
console.log(令牌);
}否则{
警报(“必须使用物理设备进行推送通知”);
}
如果(Platform.OS==='android'){
Notifications.setNotificationChannelAsync('default'{
名称:“默认值”,
重要性:Notifications.AndroidImportance.MAX,
振动模式:[0,250,250,250],
浅色:“#FF231F7C”,
});
}
返回令牌;

}
确保从“expo”导入{Notifications},而不是从“expo Notifications”导入。 也有同样的问题,但后来尝试从“世博会”中导入,结果成功了。

确保您处于托管工作流中,如果您处于裸机状态,则应指定 {experienceId}

文档中的代码示例:

    import Constants from 'expo-constants';
import * as Notifications from 'expo-notifications';

export async function registerForPushNotificationsAsync(userId: string) {
  let experienceId = undefined;
  if (!Constants.manifest) {
    // Absence of the manifest means we're in bare workflow
    experienceId = '@username/example';
  }
  const expoPushToken = await Notifications.getExpoPushTokenAsync({
    experienceId,
  });
  await fetch('https://example.com/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      userId,
      expoPushToken,
    }),
  });
}
经验ID(字符串)--令牌应归属于的体验ID。默认为expo Constants公开的Constants.manifest.ID。在裸工作流中,您必须提供一个形状为@username/projectSlug的值,其中username是项目关联的expo帐户,projectSlug是app.json中的slug


有关详细信息:

我出现此错误是因为我没有登录Expo(使用Expo客户端).

您是在真实设备上还是在模拟器上执行此操作?使用Android中的Expo应用程序的真实设备有人能找到解决此问题的方法吗?为什么我们需要使用“Expo”模块而不是文档中所述的“Expo通知”。经过长时间的研究,终于找到了解决方案。实际上,Expo文档将导入*作为通知来自“expo notifications”的ns;但实际上可用于从“expo”导入{notifications};此外,您必须登录expo cli。检查此问题:此处存在相同的问题。找到解决方案了吗?(托管工作流)相同的问题持续存在此问题是使用此处描述的LegacyNotifications。从expo中弹出后,react native项目中存在相同的问题