5

我正在使用 React Native 推送通知https://github.com/zo0r/react-native-push-notification 目前,它会在关闭应用程序后收到推送通知。

  1. 如何将我的 pushMessage(chat) 传递到通知中?

  2. 如何让它在前台(当应用程序仍然打开时)和后台(不打开应用程序)接收推送通知 *目前它会在关闭应用程序后收到通知

我应该处理哪一部分?

App.js
--------
PushNotification.configure({
    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );

        // process the notification . * this will overwrite the My Notification 1 below
        PushNotification.localNotification({
            foreground: true,
            title: "My Notification Title",
            message: "My Notification 2", // (required)
        });

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },


});


class App extends Component{
    componentDidMount(){
        const connection = signalr.hubConnection('https://api.abc.com');
        const proxy = connection.createHubProxy('chatHub');

        proxy.on('pushMessage', (chat) => {
            PushNotification.localNotification({
               foreground: true,
               title: "My Notification Title",
               message: "My Notification 1", // (required)
            });
        });
    }
}
4

0 回答 0