Search code examples
androidreactjsreact-nativeexpopush

Expo Push Notification not working on standalone app


I made the setup for push notifications using the expo push system and it works fine when using the app through ExpoGo. But in the installed app from the play store, it doesnt work. Debugging the app I found out that the

token = (await Notifications.getExpoPushTokenAsync()).data;

is returning nothing because the alert after it never runs.

async function registerForPushNotificationsAsync() {
    let token;
    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;
    }
    alert('1')
    token = (await Notifications.getExpoPushTokenAsync()).data;
    alert('2')
    if (Platform.OS === 'android') {
      Notifications.setNotificationChannelAsync('default', {
        name: 'default',
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: '#FF231F7C',
      });
    }

    //sending the token to my api
    api.put('xxx', {
      notification_token: token,
    });
  }

What should I do? Is anything I am missing? I just used the codes given in the docs https://docs.expo.io/push-notifications/overview/


Solution

  • I found the solution.

    The point is that in the docs of setup the push notifications, for some reason they dont mention there that is necessary to setup a firebase account to push notifications work in the standalone app even if I'm using the expo system.

    Discovered the solution in this link https://github.com/expo/expo/issues/9770

    And setted up the FCM with this link https://docs.expo.io/push-notifications/using-fcm/