Swift:出现后杀死接收者

标签 swift quickblox receiver

我在 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/

相关文章:

ios - 在 XCode 8 中获取 Firebase MobileAssetError 警告

Swift - SKSpritenode 的 bool 属性 - 从父级中删除?

ios - 在 for 循环中运行多个 URLRequest,先完成后执行

ios - 适用于 iOS 的 Quickblox : how do I extract locations only in 100 km area?

go - 接收方是否确定应用哪种方法?

ios - 如何删除 Storyboard中 UIView 的底部空白区域?

ios - Thread 1 : EXC_BAD_ACCESS (code=1, address=0x20) 当subView

ios - QMChatViewController 导致 "Cannot assign to property: ' self' 是不可变的

pointers - 如何在 Go 中使用接收器?

java - 在 Java 中,MIDI 信息到达接收器后如何访问它