按下@时,请包含电话号码和显示名称

时间:2019-07-06 17:20:16

标签: ios swift autocomplete messagekit

目前,我已经包含了显示名称和电话号码,如代码所示。但是,当我向用户显示消息时,它应该显示@displayName,将消息发送到服务器时,它应该显示为@phoneNumber。如何具有此功能?

我要在autocompleteManager中返回带有AutoCompletion对象的文本和上下文,如何检索该上下文并将其发送到服务器

当前的autocompleteManager功能

   func autocompleteManager(_ manager: AutocompleteManager, autocompleteSourceFor prefix: String) -> [AutocompleteCompletion] {
       if prefix == "@" {
           return self.contactsArray
               .map { user in
                   return AutocompleteCompletion(text: user.displayName,
                                                 context: ["id": user.phoneNumber,"text":user.displayName])
           }
       }else if prefix == "#" {
           return self.tasks
               .map { task in
                   return AutocompleteCompletion(text: task.title, context: ["id":task.documentID])
           }
       }
       return []
   }

输入栏didPressSendButtonWith

    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        if let text = inputBar.inputTextView.text  {
            guard let id = serviceManager?.discussionService?.addMessage() else { return }
            let textWithNumber = replaceUserName(text: text)
            let message = DisscussionMessage(text: textWithNumber, user: (serviceManager?.authService?.getCurrentUser())!, messageId: id, date: Date(), groupId: self.group?.documentID ?? "")

            self.saveMessage(message)
        }
        inputBar.inputTextView.text = ""
        messagesCollectionView.scrollToBottom()
    }

在replaceUserName()函数中,我接受文本并替换开头带有@的名称。

0 个答案:

没有答案