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

查看:32
本文介绍了应用程序处于前台时的 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 日已过时.请参阅 https://stackoverflow.com/a/60344280/2441420 了解如何在应用程序处于前台时显示 iOS 通知

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天全站免登陆