首页 > 解决方案 > getExpoPushTokenAsync 在 Android 测试设备上没有响应

问题描述

我知道有一些关于“独立”设备的类似帖子,但这是关于与 Expo XDE 相关的(仍然)测试设备。

简而言之:

我正在尝试使用 getExpoPushTokenAsync 获取推送通知令牌,这对 iphone 非常有效,但不适用于 android 手机

代码: token = await Notifications.getExpoPushTokenAsync(); –> 返回 iphone 的令牌,但在 Android 上没有任何反应(甚至没有任何后续的 console.log)

就在之前: const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); –> 返回“授予”</p>

我正在使用:“expo”:“^36.0.0”,

// if no existing permission ask user for permission
   console.log("status: -" + status + '-');
    if (status !== 'granted') {
      // Android remote notification permissions are granted during the app
      // install, so this will only ask on iOS
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }

    // If no permission, exit ...
    if (finalStatus !== 'granted') {
      return;
    }

    // Get the token that uniquely identifies this device
    console.log("BEFORE TOKEN....");
    let token = await Notifications.getExpoPushTokenAsync();
    console.log("TOKEN: " + token);

输出安卓:

status: -granted-
TOKEN BEFORE....

输出 iPhone:

status: -granted-
TOKEN BEFORE....
TOKEN: ExponentPushToken[Xxxxx_Xxxxxxxxxxxxxx]

标签: androidreact-nativereact-native-androidexpo

解决方案


推荐阅读