From a25010e2bab0a6bc90398505d95182a5a62d1847 Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 17 Jul 2023 17:28:39 +0800 Subject: [PATCH] fix: ios crash while close app --- ios/Classes/RTMCallManager.swift | 18 +++++++++++++++--- ios/Classes/SwiftAgoraRtmPlugin.swift | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) 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) {