如何在前台和后台接收本机推送通知

时间:2018-01-24 15:25:59

标签: react-native react-native-ios react-native-push-notification

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

  1. 如何将pushMessage(聊天)传递给通知?

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

  3. 我应该在哪个部分工作?

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

0 个答案:

没有答案