0
votes

I use Expo push Notifications to send Notifications to GSM using push token. My code is :

  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();
}

When i use Expo to run the App i granted manually the permissions to get the token, but now i ejected to app to run IOS project with Xcode. I got an error that i can't get push token : Failed to get push token for push notification

2

2 Answers

1
votes

The function getExpoPushTokenAsync() is for Expo app. If you eject your app, she will no longer depends on Expo and will no longer have access to expo specific function.

you may read :

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

an easy way to make push notification on react-native is to use firebase cloud messaging.

1
votes

Expo Ejected Apps need to use react-native libraries for notifications. I recommend: https://github.com/zo0r/react-native-push-notification

There are currently, expo-kit solutions. But those will be depreciated soon in favor of the bare workflow. 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.