如何通过反应原生

时间:2018-01-23 12:41:24

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

我正在使用 React Native Push Notification https://github.com/zo0r/react-native-push-notification

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

当从服务器收到推送消息时,我有这个onNotification和PushNotificationIOS错误。 enter image description here

设备上的

错误 enter image description here

我应该在哪个部分工作?

ps:我不明白这项工作如何 - > 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 个答案:

答案 0 :(得分:0)

PushNotificationIOS是一个由react-native提供的API,所以也许你从react-native导入它就像这样

import { PushNotificationIOS } from 'react-native'

答案 1 :(得分:0)

PushNotification使用PushNotificationIOS。您必须添加并导入它。

执行以下操作。

如果使用Yarn,请在控制台中运行此程序:yarn add @react-native-community/push-notification-ios ... ...或使用NPM来运行此命令:npm install @react-native-community/push-notification-ios

然后,在使用PushNotification的文件中,将此行添加到其他导入中: import PushNotificationIOS from "@react-native-community/push-notification-ios"