Skip to content

Commit e4ea913

Browse files
fix(ios): Crash "Unexpectedly found nil while implicitly unwrapping an Optional value" (#136)
1 parent 116e8a3 commit e4ea913

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

plugin/ios/Plugin/Map.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GMViewController: UIViewController {
1414
var cameraPosition: [String: Double]!
1515
var minimumClusterSize: Int?
1616
var mapId: String?
17+
var onViewDidLoad: (() -> Void)?
1718

1819
private var clusterManager: GMUClusterManager?
1920

@@ -34,6 +35,7 @@ class GMViewController: UIViewController {
3435
}
3536

3637
self.view = GMapView
38+
self.onViewDidLoad?()
3739
}
3840

3941
func initClusterManager(_ minClusterSize: Int?) {
@@ -94,10 +96,12 @@ public class Map {
9496
self.delegate = delegate
9597
self.mapViewController = GMViewController()
9698
self.mapViewController.mapId = config.mapId
97-
99+
self.mapViewController.onViewDidLoad = { [weak self] in
100+
self?.finishMapConfiguration()
101+
}
98102
self.render()
99103
}
100-
104+
101105
func render() {
102106
DispatchQueue.main.async {
103107
self.mapViewController.mapViewBounds = [
@@ -106,23 +110,28 @@ public class Map {
106110
"x": self.config.x,
107111
"y": self.config.y
108112
]
109-
113+
110114
self.mapViewController.cameraPosition = [
111115
"latitude": self.config.center.lat,
112116
"longitude": self.config.center.lng,
113117
"zoom": self.config.zoom
114118
]
115-
119+
116120
self.targetViewController = self.getTargetContainer(refWidth: self.config.width, refHeight: self.config.height)
117-
121+
118122
if let target = self.targetViewController {
119123
target.tag = Map.MAP_TAG
120124
target.removeAllSubview()
121125
self.mapViewController.view.frame = target.bounds
122126
target.addSubview(self.mapViewController.view)
123-
self.mapViewController.GMapView.delegate = self.delegate
124127
}
128+
}
129+
}
125130

131+
func finishMapConfiguration() {
132+
DispatchQueue.main.async {
133+
self.mapViewController.GMapView.delegate = self.delegate
134+
126135
if let styles = self.config.styles {
127136
do {
128137
self.mapViewController.GMapView.mapStyle = try GMSMapStyle(jsonString: styles)

0 commit comments

Comments
 (0)