Search code examples
iosobjective-cxcodecrash-reportscrittercism

Xcode 8.2 app Crash -[viewcontroller .cxx_destruct] symbolicated crash report


App is experiencing following crash and unable to understand the cause behind of this crash. This crash report I got it from App Store. This is the crash report screenshot

-[viewcontroller .cxx_destruct] symbolicated crash report

It is mostly affecting on iOS 10.2. In this class I'm using Google Maps, Pageviewcontroller and Timer. So, anyone can tell me how to figure out it?


Solution

  • This crash is happening due to fetching user current location from Google Maps by using addObserver forKeyPath:@"myLocation" options:NSKeyValueObservingOptionNew.

    While dealloc Google Maps, that time you need to remove this Observer. Otherwise app will crash with following error

    NSInternalInconsistencyException: An instance 0x1759f350 of class GMSMapView was deallocated while key value observers were still registered with it. Current observation info: ( Context: 0x0, Property: 0x177a4490> )

    you need to addObserver before adding Google Maps to mapView like following:

    // Listen to the myLocation property of GMSMapView.
    [mapView_ addObserver:self
             forKeyPath:@"myLocation"
                options:NSKeyValueObservingOptionNew
                context:NULL];
    
    self.view = mapView_;
    
    // Ask for My Location data after the map has already been added to the UI.
    dispatch_async(dispatch_get_main_queue(), ^{
       mapView_.myLocationEnabled = YES;
    });
    
    #pragma mark - KVO updates
    
    - (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {
    if (!firstLocationUpdate_) {
    // If the first location update has not yet been received, then jump to that
    // location.
      firstLocationUpdate_ = YES;
      CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
    mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
                                                     zoom:14];
     }
    }
    

    then add this code also for removing the observer

    - (void)dealloc {
    [mapView_ removeObserver:self
                forKeyPath:@"myLocation"
                   context:NULL];
    }
    

    for more details: Google Maps iOS SDK, Getting Current Location of user