-1

在 MessageKit 中发送消息时如何实现有关错误的信息?未发送消息时我需要显示信息。有任何想法吗?

4

1 回答 1

7

在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 { $0.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您可以didTapAccessoryView在委托中实现的点击MessageCellDelegate

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
}

你可以在这里有另一个例子

注意:重试的请求部分不是MessageKit的一部分,只有聊天的 UI 是MessageKit的工作

希望我的回答对你有帮助

于 2018-12-02T07:38:03.993 回答