Expo push notifications stopped working in production

Viewed 493

I'm using Expo to develop both Android and iOS at same time. Notifications were working fine for several weeks, and then out of no where stopped working in production, even though I did not update the app during this time.

Server-side, everything is still fine, and notifications are being pushed. In dev, notifications are still being received and handled properly, but in production, it's crickets.

Has anyone else experienced this / what could be causing this?

Here is my code:

class Dashboard extends Component {

  constructor(props) {
    super(props);
    this.state = {
      notificationsSet: false,
    }

  }

  componentDidMount() {
    this.registerForPushNotificationsAsync(this.props.currentUser.currentUser.id, this.props.currentUser.authToken)

   savePushToken = (userId, pushToken, token) => {
    //API call to save push token to database
    apiHelper
      .savePushToken(userId, pushToken, token)
      .then(res => {
        return
      })
      .catch(err => console.log("err saving", err));
  };

  handleNotification = notification => {
    this.props.setNotification({ notification })
  }

  registerForPushNotificationsAsync = async (userId, token) =>{
    //requesting if user would like to turn on notifications
    const { status: existingStatus } = await Permissions.getAsync(
      Permissions.NOTIFICATIONS
    );
    //this checks if notifications is turned on for the app --- "granted"
    let finalStatus = existingStatus;
    if (existingStatus !== "granted") {
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

      finalStatus = status;
    }
    if (finalStatus !== "granted") {
      return;
    }    //if "granted" then get push notifications and calls this.savepushtoken to save into the API

    let pushToken = await Notifications.getExpoPushTokenAsync();

    this.subscription = Notifications.addListener(this.handleNotification);
    this.savePushToken(userId, pushToken, token);
  };

     render() {
      return(...)
     }
  }
0 Answers
Related