Skip to content

Commit b2bd73f

Browse files
authored
Merge pull request react-native-maps#2501 from guoliang1206/master
[iOS] Fixed issue that app will crash after trigger Marker onDragEnd
2 parents d89b0b8 + b104afc commit b2bd73f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/ios/AirMaps/AIRMapManager.m

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ @interface AIRMapManager() <MKMapViewDelegate>
3737

3838
@end
3939

40-
@implementation AIRMapManager
40+
@implementation AIRMapManager{
41+
BOOL _hasObserver;
42+
}
4143

4244
RCT_EXPORT_MODULE()
4345

@@ -704,11 +706,12 @@ - (void)mapView:(AIRMap *)mapView
704706
if (mapView.onMarkerDragEnd) mapView.onMarkerDragEnd(event);
705707
if (marker.onDragEnd) marker.onDragEnd(event);
706708

707-
[view removeObserver:self forKeyPath:@"center"];
709+
if(_hasObserver) [view removeObserver:self forKeyPath:@"center"];
710+
_hasObserver = NO;
708711
} else if (newState == MKAnnotationViewDragStateStarting) {
709712
// MapKit doesn't emit continuous drag events. To get around this, we are going to use KVO.
710713
[view addObserver:self forKeyPath:@"center" options:NSKeyValueObservingOptionNew context:&kDragCenterContext];
711-
714+
_hasObserver = YES;
712715
if (mapView.onMarkerDragStart) mapView.onMarkerDragStart(event);
713716
if (marker.onDragStart) marker.onDragStart(event);
714717
}

0 commit comments

Comments
 (0)