应用程序在前台时的iOS Expo推送通知 [英] IOS Expo Push Notifications when app is in foreground

查看:134
本文介绍了应用程序在前台时的iOS Expo推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读博览会文档:

对于iOS,明智的做法是处理 在应用程序前台时收到,因为否则用户 永远不会看到他们.应用程式发出时收到的通知 在iOS上显示的前景不会显示在系统通知列表中.一种 常见的解决方案是仅手动显示通知.为了 例如,如果您在Messenger for iOS上收到消息,请安装该应用 前景,但没有打开该对话,您将看到 自定义从屏幕顶部向下滑动通知 通知界面.

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用于显示此类消息?还是应该创建自己的警报组件?从文档中还不清楚.

What I don't understand is what is the best approach for that? is there an Expo API for showing such messages? or should I create an alert component of my own? It is not really clear from the docs.

谢谢.

推荐答案

该答案截至2020年2月20日已过时.请参阅

This answer is outdated as of February 20, 2020. Please see https://stackoverflow.com/a/60344280/2441420 for how to show iOS Notification when your application is in the Foreground

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

There isn't an Expo API for showing those messages. You can use any 'toast' library of your choosing and display the notification message, but that should be all your code.

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

For example, this is how we are doing right now:

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);
  }

}

Toast库包括:

react-native-easy-toast

react-native-simple-toast

这篇关于应用程序在前台时的iOS Expo推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆