在 MessageKit 中发送消息时如何实现有关错误的信息? SWIFT
How to implement info about error when send message in MessageKit? SWIFT
如何实现MessageKit发送消息报错信息?
当消息未发送时,我需要显示信息。有什么想法吗?
How to implement info about error when send message in MessageKit ?
要使用 MessageKit 显示有关消息的信息,您需要使用 accessoryView
它是消息左侧或右侧的视图,其中您可以添加按钮或图像来显示信息。你可以这样显示信息
在MessagesDisplayDelegate
中你可以实现方法configureAccessoryView
这是一个如何操作的例子:
在这个例子中,我们简单地向视图添加一个按钮
func configureAccessoryView(_ accessoryView: UIView,
for message: MessageType,
at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) {
// Remove old views from the previous use
accessoryView.subviews.forEach { [=10=].removeFromSuperview() }
// Handle retry logic, you can display this button only if the upload fail as example
let button = UIButton(type: .infoLight)
button.tintColor = .red
accessoryView.addSubview(button)
button.frame = accessoryView.bounds
button.isUserInteractionEnabled = false // respond to accessoryView tap through `MessageCellDelegate`
accessoryView.layer.cornerRadius = accessoryView.frame.height / 2
}
要检测 accessoryView
上的点击,您可以在委托 MessageCellDelegate
中实现 didTapAccessoryView
func didTapAccessoryView(in cell: MessageCollectionViewCell) {
guard let indexPath = messagesCollectionView.indexPath(for: cell) else { return }
// Handle tap here
// As example here in my apps I display an actionSheet to cancel or retry
}
你可以再举一个例子here
注意:重试的请求部分不是MessageKit的一部分,只是您聊天的UI是[=39=的工作]MessageKit
希望我的回答对你有帮助
如何实现MessageKit发送消息报错信息? 当消息未发送时,我需要显示信息。有什么想法吗?
How to implement info about error when send message in MessageKit ?
要使用 MessageKit 显示有关消息的信息,您需要使用 accessoryView
它是消息左侧或右侧的视图,其中您可以添加按钮或图像来显示信息。你可以这样显示信息
在MessagesDisplayDelegate
中你可以实现方法configureAccessoryView
这是一个如何操作的例子: 在这个例子中,我们简单地向视图添加一个按钮
func configureAccessoryView(_ accessoryView: UIView,
for message: MessageType,
at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) {
// Remove old views from the previous use
accessoryView.subviews.forEach { [=10=].removeFromSuperview() }
// Handle retry logic, you can display this button only if the upload fail as example
let button = UIButton(type: .infoLight)
button.tintColor = .red
accessoryView.addSubview(button)
button.frame = accessoryView.bounds
button.isUserInteractionEnabled = false // respond to accessoryView tap through `MessageCellDelegate`
accessoryView.layer.cornerRadius = accessoryView.frame.height / 2
}
要检测 accessoryView
上的点击,您可以在委托 MessageCellDelegate
didTapAccessoryView
func didTapAccessoryView(in cell: MessageCollectionViewCell) {
guard let indexPath = messagesCollectionView.indexPath(for: cell) else { return }
// Handle tap here
// As example here in my apps I display an actionSheet to cancel or retry
}
你可以再举一个例子here
注意:重试的请求部分不是MessageKit的一部分,只是您聊天的UI是[=39=的工作]MessageKit
希望我的回答对你有帮助