首页 > 解决方案 > Expo.Notifications.addListener() 未触发(iOS 独立应用程序)

问题描述

我正在尝试在我的组件中使用 Expo.Notifictions.addListener(在 iOS 独立版本上),但尽管成功接收到通知,但它不会触发。

addListener() 被放置在componentDidMount()函数内部。

Expo.Notifications.addListener(this.handleNotification);

handleNotification = () => {
  this.setState({
    something: 3,
  });
};

标签: iosreact-nativenotificationsexpo

解决方案


您没有将回调添加到您的 addListener 函数中。

componentDidMount(){
    Notifications.addListener(notification => {
      console.log(notification);  
    });
}

推荐阅读