From c07dca32c1808084c8db2a5f385e8eaa67dbad1e Mon Sep 17 00:00:00 2001 From: OS-pedrogustavobilro Date: Mon, 22 Sep 2025 17:55:35 +0100 Subject: [PATCH 1/2] fix(ios): Crash "Unexpectedly found nil while implicitly unwrapping an Optional value" The crash was occuring inside `render` method in `Map.swift`. The creation of `GMapView` sometimes was occuring after trying to acces it as `self.mapViewController.GMapView`. In such case the value was still nil, resulting in the crash when trying to unwrap the value. The fix involved only accessing `self.mapViewController.GMapView` after `viewDidLoad` finishes and `GMapView` is initialized. --- plugin/ios/Plugin/Map.swift | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin/ios/Plugin/Map.swift b/plugin/ios/Plugin/Map.swift index 1bbd63b..89faa21 100644 --- a/plugin/ios/Plugin/Map.swift +++ b/plugin/ios/Plugin/Map.swift @@ -14,6 +14,7 @@ class GMViewController: UIViewController { var cameraPosition: [String: Double]! var minimumClusterSize: Int? var mapId: String? + var onViewDidLoad: (() -> Void)? private var clusterManager: GMUClusterManager? @@ -34,6 +35,7 @@ class GMViewController: UIViewController { } self.view = GMapView + self.onViewDidLoad?() } func initClusterManager(_ minClusterSize: Int?) { @@ -94,10 +96,12 @@ public class Map { self.delegate = delegate self.mapViewController = GMViewController() self.mapViewController.mapId = config.mapId - + self.mapViewController.onViewDidLoad = { [weak self] in + self?.finishMapConfiguration() + } self.render() } - + func render() { DispatchQueue.main.async { self.mapViewController.mapViewBounds = [ @@ -106,23 +110,28 @@ public class Map { "x": self.config.x, "y": self.config.y ] - + self.mapViewController.cameraPosition = [ "latitude": self.config.center.lat, "longitude": self.config.center.lng, "zoom": self.config.zoom ] - + self.targetViewController = self.getTargetContainer(refWidth: self.config.width, refHeight: self.config.height) - + if let target = self.targetViewController { target.tag = Map.MAP_TAG target.removeAllSubview() self.mapViewController.view.frame = target.bounds target.addSubview(self.mapViewController.view) - self.mapViewController.GMapView.delegate = self.delegate } + } + } + func finishMapConfiguration() { + DispatchQueue.main.async { + self.mapViewController.GMapView.delegate = self.delegate + if let styles = self.config.styles { do { self.mapViewController.GMapView.mapStyle = try GMSMapStyle(jsonString: styles) From 116e8a37f1a7d67feb6204126921f57f665aafbb Mon Sep 17 00:00:00 2001 From: OS-pedrogustavobilro Date: Mon, 22 Sep 2025 18:41:44 +0100 Subject: [PATCH 2/2] chore: fix README --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 30d0b95..6ac6da4 100644 --- a/README.md +++ b/README.md @@ -1274,13 +1274,6 @@ Supports markers of either either "legacy" or "advanced" types. google.maps.Marker | google.maps.marker.AdvancedMarkerElement -#### Marker - -Supports markers of either either "legacy" or "advanced" types. - -google.maps.Marker | google.maps.marker.AdvancedMarkerElement - - ### Enums