【问题标题】:Why does app crash after MapView.Marker dragged?为什么 MapView.Marker 拖动后应用程序崩溃?
【发布时间】:2017-03-06 13:59:01
【问题描述】:

我的应用中有来自react-native-maps@0.12.2MapView 组件。在 MapView 中,我有一个可拖动的 MapView.Marker。 问题是当我拖动这个标记应用程序时,有时突然异常崩溃。是的,有时这很奇怪。

Terminating app due to uncaught exception 'NSRangeException', reason:'Cannot remove an observer <AIRMapManager 0x6080000096b0> for the key path "center" from <AIRMapMarker 0x7fdb4a68f4f0> because it is not registered as an observer.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c9e0b2b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010b89b281 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ca49685 +[NSException raise:format:] + 197
    3   Foundation                          0x000000010b3b8a38 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 497
    4   Foundation                          0x000000010b3b87ec -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 84
    5   mojazastavka_ios                    0x000000010aed6949 -[AIRMapManager mapView:annotationView:didChangeDragState:fromOldState:] + 1321
    6   MapKit                              0x000000010e66dd9a -[MKMapView _annotationViewDragStateChanged:] + 440
    7   CoreFoundation                      0x000000010c97fc2c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    8   CoreFoundation                      0x000000010c97fb29 _CFXRegistrationPost + 425
    9   CoreFoundation                      0x000000010c97f892 ___CFXNotificationPost_block_invoke + 50
    10  CoreFoundation                      0x000000010c943132 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
    11  CoreFoundation                      0x000000010c942291 _CFXNotificationPost + 673
    12  Foundation                          0x000000010b367328 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    13  MapKit                              0x000000010e73f916 -[MKAnnotationView setDragState:animated:] + 224
    14  MapKit                              0x000000010e7ebb4f -[MKAnnotationContainerView _dropDraggingAnnotationViewAnimated:] + 276
    15  MapKit                              0x000000010e66b928 -[MKMapView _dropDraggingAnnotationView:] + 91
    16  MapKit                              0x000000010e66bbac -[MKMapView handleLongPress:] + 604
    17  UIKit                               0x000000010f553751 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
    18  UIKit                               0x000000010f55b54f _UIGestureRecognizerSendTargetActions + 109
    19  UIKit                               0x000000010f558f03 _UIGestureRecognizerSendActions + 225
    20  UIKit                               0x000000010f5581c6 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981
    21  UIKit                               0x000000010f544728 _UIGestureEnvironmentUpdate + 1219
    22  UIKit                               0x000000010f544219 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
    23  UIKit                               0x000000010f5433e0 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
    24  UIKit                               0x000000010f092baa -[UIWindow sendEvent:] + 4092
    25  UIKit                               0x000000010f03f274 -[UIApplication sendEvent:] + 352
    26  UIKit                               0x000000010f81efa8 __dispatchPreprocessedEventFromEventQueue + 2932
    27  UIKit                               0x000000010f816f74 __handleEventQueue + 1115
    28  CoreFoundation                      0x000000010c986c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    29  CoreFoundation                      0x000000010c96c0af __CFRunLoopDoSources0 + 527
    30  CoreFoundation                      0x000000010c96b5df __CFRunLoopRun + 911
    31  CoreFoundation                      0x000000010c96aff6 CFRunLoopRunSpecific + 406
    32  GraphicsServices                    0x0000000112905979 GSEventRunModal + 62
    33  UIKit                               0x000000010f021bb1 UIApplicationMain + 159
    34  mojazastavka_ios                    0x000000010aecd67f main + 111
    35  libdyld.dylib                       0x00000001109fc66d start + 1
    36  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我真的不知道是什么原因造成的,代码是根据官方的例子:

import React, {Component} from 'react';
import MapView from 'react-native-maps';
import MyCustomCallout from './MyCustomCallout';

export default class Map extends Component{

  constructor(props) {
    super(props);

    let marker = null;
  }

  render(){
      return (
          <MapView>
              <MapView.Marker 
                draggable 
                onDragEnd={e => console.log(e.nativeEvent)}
                coordinate={{
                  latitude: this.props.latitude,
                  longitude: this.props.longitude
                }}
                ref={ref => this.marker = ref }
                image={finishImg}>
                  <MyCustomCallout type={'FINISH'}  descriptionText={this.props.destinationName} />
              </MapView.Marker>
          </MapView>
      );
  }
}

【问题讨论】:

    标签: javascript ios react-native android-mapview marker


    【解决方案1】:

    已解决,方法是从模拟器中删除应用并重建项目。原解决方案here

    【讨论】:

      猜你喜欢
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多