加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 当应用程序处于前台时,IOS Expo推送通知

发布时间:2020-12-15 20:32:26 所属栏目:百科 来源:网络整理
导读:从世博会文档中读取: For iOS,you would be wise to handle push notifications that are received while the app is foregrounded,because otherwise the user will never see them. Notifications that arrive while the app are foregrounded on iOS do
从世博会文档中读取:

For iOS,you would be wise to handle push notifications that are
received while the app is foregrounded,because otherwise the user
will never see them. Notifications that arrive while the app are
foregrounded on iOS do not show up in the system notification list. A
common solution is to just show the notification manually. For
example,if you get a message on Messenger for iOS,have the app
foregrounded,but do not have that conversation open,you will see the
notification slide down from the top of the screen with a custom
notification UI.

我不明白的是什么是最好的方法?是否有用于显示此类消息的Expo API?或者我应该创建自己的警报组件?从文档中可以清楚地看出来.

谢谢.

解决方法

没有用于显示这些消息的Expo API.您可以使用您选择的任何“Toast”库并显示通知消息,但这应该是您的所有代码.

例如,这就是我们现在正在做的事情:

export default class HomeScreen extends React.Component {

  componentDidMount() {
    this.notificationSubscription = Notifications.addListener(
      (notification) => this.handlePushNotification(notification),);
  }

  handlePushNotification(notification) {
    const { navigation } = this.props;
    PushNotificationsService.handleNotification(notification,navigation);
  }

(……)

import Toast from 'react-native-root-toast';

export default class PushNotificationsService {

  static handleNotification(notification,navigation) {

    if (notification.data.screen && notification.origin === 'selected') {
      navigation.navigate(notification.data.screen);
    }
    Toast.show(notification.data.message);
  }

}

吐司图书馆包括:

> react-native-root-toast
> react-native-easy-toast
> react-native-simple-toast

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读