React Native Expo Ejected App,无法从设备获取推送令牌

React Native Expo Ejected App, can't get push token from Device

我使用 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 用于 运行 应用程序时,我手动授予了获取令牌的权限,但现在我将应用程序弹出到 运行 IOS 项目 Xcode. 我收到无法获取推送令牌的错误: 无法获取推送通知的推送令牌

函数 getExpoPushTokenAsync() 适用于 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.

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

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

Deprecating ExpoKit in favor of the bare workflow. We’re continuing to invest in building tooling and documentation around the bare workflow. We believe that this workflow is strictly better than ExpoKit and has lots of advantages for developers, such as full compatibility with libraries in the React Native ecosystem, easier upgrades, and more modular native code that doesn’t include all of the libraries in the Expo monolith. The bare workflow is the easiest and quickest way to achieve optional modules — that is, including native code for only the Expo modules you actually use.