gpt4 book ai didi

react-native - 应用程序在前台时的iOS Expo推送通知

转载 作者:行者123 更新时间:2023-12-04 12:27:47 27 4
gpt4 key购买 nike

从博览会文档中读取:

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

谢谢。

最佳答案

该答案截至2020年2月20日已过时。有关在前景中使用应用程序时如何显示iOS通知的信息,请参阅https://stackoverflow.com/a/60344280/2441420

没有显示这些消息的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);
}

}

toast 库包括:
  • react-native-root-toast
  • react-native-easy-toast
  • react-native-simple-toast
  • 关于react-native - 应用程序在前台时的iOS Expo推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48437781/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com