0
votes

Im using React Native Push Notification https://github.com/zo0r/react-native-push-notification

How can I pass my pushMessage(chat) into the notification?

I have this onNotification and PushNotificationIOS error when received push message from server. enter image description here

error on device enter image description here

which part should I work on?

ps: im not understand how this work -> notification.finish(PushNotificationIOS.FetchResult.NoData);

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

        // 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.localNotificationSchedule({
                message: "My Notification 1",
                date: new Date(Date.now())
            });
        });
    }
}
2
PushNotification not imported - Ali Faris

2 Answers

0
votes

PushNotificationIOS is an API provided by react-native so maybe you import it from react-native like so

import { PushNotificationIOS } from 'react-native'

0
votes

PushNotification uses PushNotificationIOS. You have to add and import it.

Do the following.

In the console, run this if using Yarn: yarn add @react-native-community/push-notification-ios... ... or run this if using NPM: npm install @react-native-community/push-notification-ios

Then, in your file where you use PushNotification, add this line among your other imports: import PushNotificationIOS from "@react-native-community/push-notification-ios"