【问题标题】:React Native Expo Ejected App, can't get push token from DeviceReact Native Expo Ejected App,无法从设备获取推送令牌
【发布时间】:2020-04-28 01:08:15
【问题描述】:

我使用 Expo 推送通知通过推送令牌向 GSM 发送通知。 我的代码是:

  registerForPush = async () => {
    if (Constants.isDevice) {
      const { status: existingStatus } = await Permissions.getAsync(
        Permissions.NOTIFICATIONS,
      );
      let finalStatus = existingStatus;
      if (existingStatus !== 'granted') {
        const { status } = await Permissions.askAsync(
          Permissions.NOTIFICATIONS,
        );
        finalStatus = status;
      }
      if (finalStatus !== 'granted') {
        alert('Failed to get push token for push notification!');
        return;
      }
      const gsm = await Notifications.getExpoPushTokenAsync();
      this._storeData('TOKEN_GSM', gsm);
    } else {
      alert('Must use physical device for Push Notifications');
    }
  };

async componentDidMount() {
this.registerForPush();
}

当我使用 Expo 运行应用程序时,我手动授予了获取令牌的权限,但现在我弹出应用程序以使用 Xcode 运行 IOS 项目。 我收到一个错误,我无法获取推送令牌: 推送通知获取推送令牌失败

【问题讨论】:

    标签: ios react-native push-notification expo native


    【解决方案1】:

    函数 getExpoPushTokenAsync() 用于 Expo 应用程序。 如果您退出您的应用程序,她将不再依赖 Expo,并且将不再有权访问 Expo 特定功能。

    你可以阅读:

    https://forums.expo.io/t/expokit-push-notifications-on-ejected-app-lots-of-misinformation-even-in-expo-docs-need-clarity/14670

    在 react-native 上进行推送通知的一种简单方法是使用 firebase cloud messaging.

    【讨论】:

    • 我不这么认为,世博会通知中有一个部分叫做:“使用 FCM 进行推送通知”,这是我们可以添加到世博会弹出应用程序的配置,所以我认为世博会推送是即使应用程序被弹出也可以工作
    • 哦,好吧,我的错。对不起,我对世博不太好。但无论如何,在本地实现通知仍然是一个好主意。
    • 你可能想看看expoKit
    【解决方案2】:

    Expo Ejected 应用程序需要使用 react-native 库进行通知。 我推荐:https://github.com/zo0r/react-native-push-notification

    目前有 expo-kit 解决方案。但这些很快就会贬值,有利于裸露的工作流程。 https://blog.expo.io/expo-sdk-34-is-now-available-4f7825239319

    弃用 ExpoKit 以支持裸工作流。 我们将继续投资于围绕裸工作流构建工具和文档。我们相信这个工作流严格来说比 ExpoKit 更好,并且对开发者有很多优势,比如完全兼容 React Native 生态系统中的库,更容易升级,以及更模块化的原生代码,不包含 Expo 中的所有库巨石。裸工作流是实现可选模块的最简单、最快捷的方式——也就是说,只包括您实际使用的 Expo 模块的本机代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 2015-07-08
      相关资源
      最近更新 更多