diff --git a/ios/Classes/RTMCallManager.swift b/ios/Classes/RTMCallManager.swift index 1c57fe3..8312f2b 100644 --- a/ios/Classes/RTMCallManager.swift +++ b/ios/Classes/RTMCallManager.swift @@ -13,19 +13,31 @@ class RTMCallManager: NSObject, AgoraRtmCallDelegate, FlutterStreamHandler { var eventChannel: FlutterEventChannel? var eventSink: FlutterEventSink? - var manager: AgoraRtmCallKit? + var client: AgoraRtmKit? var remoteInvitations: [Int: AgoraRtmRemoteInvitation] = [:] var localInvitations: [Int: AgoraRtmLocalInvitation] = [:] + var manager: AgoraRtmCallKit? { + get { + return client?.rtmCallKit + } + } init(_ client: AgoraRtmKit, _ clientIndex: Int, _ messenger: FlutterBinaryMessenger) { eventChannel = FlutterEventChannel( name: "io.agora.rtm.client\(clientIndex).call_manager", binaryMessenger: messenger ) - manager = client.getRtmCall() + self.client = client super.init() eventChannel?.setStreamHandler(self) - manager?.callDelegate = self + self.manager?.callDelegate = self + } + + deinit { + remoteInvitations.removeAll() + localInvitations.removeAll() + eventChannel = nil + client = nil } private func sendEvent(eventName: String, params: [String: Any?]) { diff --git a/ios/Classes/SwiftAgoraRtmPlugin.swift b/ios/Classes/SwiftAgoraRtmPlugin.swift index b15d7ab..f5839e1 100644 --- a/ios/Classes/SwiftAgoraRtmPlugin.swift +++ b/ios/Classes/SwiftAgoraRtmPlugin.swift @@ -26,6 +26,7 @@ public class SwiftAgoraRtmPlugin: NSObject, FlutterPlugin { public func detachFromEngine(for registrar: FlutterPluginRegistrar) { methodChannel.setMethodCallHandler(nil) + clients.removeAll() } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {