[英]React-native: display foreground notifications like background notifications with zo0r/react-native-push-notification
I have set up push notifications on my React-native app with zo0r / react-native-push-notification .我已经使用zo0r / react-native-push-notification在我的 React-native 应用程序上设置了推送通知。 It works on Android, and on iOS when the app is in background mode.当应用程序处于后台模式时,它适用于 Android 和 iOS。
However, the notification does not display when the app is in foreground mode with iOS .但是,当应用程序处于 iOS 的前台模式时,不会显示通知。 I'm aware that I have to handle the notification when in foreground mode but I'd like to display them exactly the same way there are displayed when in background mode.我知道我必须在前台模式下处理通知,但我想以与后台模式下完全相同的方式显示它们。
So I did the following:所以我做了以下事情:
import {PushNotificationIOS} from 'react-native';
PushNotification.configure({
...
onNotification: function(notification) {
if (notification.foreground) {
PushNotification.localNotification(notification);
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
...
}
But nothing happens, the notification is still not displayed, what am I missing?但是没有任何反应,通知仍然没有显示,我错过了什么?
I had to add some configuration inside the ios file AppDelegate.m
我不得不在 ios 文件AppDelegate.m
添加一些配置
Following this gist did make it work.遵循这个 要点确实使它起作用。
My code look like:我的代码看起来像:
onNotification(notification) {
if (isIos) {
if (
notification.foreground &&
(notification.userInteraction || notification.remote)
) {
PushNotification.localNotification(notification);
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
} else {
if (notification.foreground) {
PushNotification.localNotification(notification);
}
}
},
I also set popInitialNotification
to true
我还将popInitialNotification
设置为true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.