首页 > 解决方案 > 世博会推送通知在生产中停止工作

问题描述

我正在使用 Expo 同时开发 Android 和 iOS。通知在几周内都可以正常工作,然后突然停止在生产中工作,即使我在此期间没有更新应用程序。

服务器端,一切正常,正在推送通知。在开发中,通知仍在接收和正确处理,但在生产中,它是蟋蟀。

有没有其他人经历过这种情况/可能是什么原因造成的?

这是我的代码:

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

标签: push-notificationexpo

解决方案


推荐阅读