如何在MessageKit中发送消息时实现有关错误的信息?迅速

wys*_*sio -2 ios swift messagekit

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

Jul*_*ode 5

如何在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
}
Run Code Online (Sandbox Code Playgroud)

要检测点击,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
}
Run Code Online (Sandbox Code Playgroud)

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

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

希望我的回答对您有所帮助