即时通信使用React本地推送通知https://github.com/zo0r/react-native-push-notification
如何将我的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())
});
});
}
}
发布于 2018-01-23 22:13:14
PushNotificationIOS是由react-native提供的一个API,所以您可以像这样从react-native导入它。
import { PushNotificationIOS } from 'react-native'
发布于 2020-07-28 23:44:32
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"
https://stackoverflow.com/questions/48402032
复制相似问题