在聊天1:1(原生QB聊天1:1功能或2位用户的聊天室)中,如何让用户知道他的对手正在打字?它是否可以与Quickblox一起使用?
答案 0 :(得分:1)
是的,这是可能的。它被称为聊天状态通知
以下是如何在1-1聊天
中执行此操作的指南http://quickblox.com/developers/SimpleSample-chat_users-ios#Chat_State_Notifications
答案 1 :(得分:0)
Swift 4.2:
键入userA
时,我们可以使用userB
类的sendUserIsTyping()
方法向QBChatDialog
发送键入通知。
private var dialog: QBChatDialog!
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
// send typing notification to opponent user here
self.dialog.sendUserIsTyping()
}
func textFieldDidEndEditing(textField: UITextField) {
// stop typing notification when user finish his typing
self.dialog.sendUserStoppedTyping()
}
在对手用户开始和停止打字时接收打字通知
一对一聊天:
override func viewDidLoad() {
super.viewDidLoad()
// this will get called when opponent user is starts typing
self.dialog.onUserIsTyping = {(userID: UInt) in
print("Typing Starts")
}
// this will get called when opponent user is stops typing
self.dialog.onUserStoppedTyping = {(userID: UInt) in
print("Typing Stopped")
}
}
群聊:
override func viewDidLoad() {
super.viewDidLoad()
self.dialog.onUserIsTyping = {(userID: UInt) in
if self.dialog.type == .group {
// fetch username or login name from userID
QBRequest.user(withID: userID, successBlock: { (res, user) in
// check sender user id and receiver user id should not same
if self.senderID != userID {
if let name = user.fullName {
print("\(name) is typing...")
} else if let login = user.login {
print("\(login) is typing...")
}
}
}) { (response) in }
} else if self.dialog.type == .private {
print("Typing Starts...")
}
}
self.dialog.onUserStoppedTyping = {(userID: UInt) in
if self.dialog.type == .group {
//No one is typing
} else if self.dialog.type == .private {
print("Typing Stopped")
}
}
}