如何将pushMessage(聊天)传递给通知?
当从服务器收到推送消息时,我有这个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())
});
});
}
}
答案 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"