【问题标题】:How to pass data to push notification with react native如何通过本机反应将数据传递给推送通知
【发布时间】:2018-01-23 12:41:24
【问题描述】:

我正在使用 React Native 推送通知https://github.com/zo0r/react-native-push-notification

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

当收到来自服务器的推送消息时,我有这个 onNotification 和 PushNotificationIOS 错误。

设备错误

我应该处理哪一部分?

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

【问题讨论】:

  • PushNotification 未导入

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


【解决方案1】:

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

import { PushNotificationIOS } from 'react-native'

【讨论】:

    【解决方案2】:

    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"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 2019-06-03
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多