diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift index f49b5323..eabac9ae 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift @@ -133,7 +133,8 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle _viewRegistry.unregisterCarPlayView() } else { if let _viewId { - _viewRegistry.unregisterView(viewId: _viewId) + let viewInstanceId = ObjectIdentifier(self) + _viewRegistry.unregisterView(viewId: _viewId, viewInstanceIdToUnregister: viewInstanceId) } } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift index d1c7bb82..153615fd 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift @@ -33,16 +33,16 @@ class GoogleMapsNavigationViewRegistry { ) func registerView(viewId: Int64, view: GoogleMapsNavigationView) { - queue.async(flags: .barrier) { [weak self] in - DispatchQueue.main.async { - self?.views[viewId] = view - } + queue.sync(flags: .barrier) { [weak self] in + self?.views[viewId] = view } } - func unregisterView(viewId: Int64) { + func unregisterView(viewId: Int64, viewInstanceIdToUnregister: ObjectIdentifier) { queue.async(flags: .barrier) { [weak self] in - DispatchQueue.main.async { + if let registeredView = self?.views[viewId], + ObjectIdentifier(registeredView) == viewInstanceIdToUnregister + { self?.views.removeValue(forKey: viewId) } }