我在 ViewControllerChat
中使用以下代码作为接收器:
func chatDidReceive(_ message: QBChatMessage) {
print("REC")
}
如果我从 ViewControllerHome
转到 ViewControllerChat
并且我收到聊天,为我打印一次 REC
如果我通过下面的代码从 ViewControllerChat
转到 ViewControllerHome
并返回 ViewControllerChat
并且我收到聊天,为我打印两次 REC :
let goController: UIViewController mainStoryboard.instantiateViewController(withIdentifier: "ViewControllerHome")
self.present(goController, animated: true, completion: nil)
这是我的计划:
1- 从家里我去聊天
2- 在聊天中我收到一次 REC
3-我带礼物回家
4- 我从家里回来聊天并收到两次 REC
如果我多次打开聊天,我会得到多次 REC
但我想要在呈现 ViewControllerChat
之后,我的 chatDidReceive
被杀死!
最佳答案
当试图关闭 ViewControllerChat
时尝试移除委托(delegate):
QBRTCClient.instance().removeDelegates
由于多次接收同一条消息的原因应该是您在每次 ViewControllerChat
加载中分配委托(delegate)的方式。也许创建一个特定的服务来实现它会更好。
关于Swift:出现后杀死接收者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53373573/