Occasionally ios MKMapView Crashes when going to other screen and comeback to MapScreen

5

In my IOS App I declared Map contained view controller as a shared instance.

Exception Type:  EXC_BAD_ACCESS (SIG SEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000028
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:

0   VectorKit                       0x37058b86 __64-[VKMapCanvas 
animateToMapRegion:pitch:yaw:duration:completion:]_block_invoke_0168 + 50

1   VectorKit                       0x37003bee -[VKAnimation _stopAnimation:] + 38

2   VectorKit                       0x36fcd4a8 -[VKAnimation onTimerFired:] + 48

3   VectorKit                       0x36fcd2d0 -[VKMainLoop displayTimerFired:] + 352

4   QuartzCore                      0x3ab6706c

CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 156

5   QuartzCore                    0x3ab66fc4 CA::Display::IOMFBDisplayLink::callback(__ IOMobile Frame buffer*, unsigned long long, unsigned long long, unsigned long long, void*) + 
60
6   IO Mobile Frame buffer              0x34609fd4 IO Mobile Frame buffer VsyncNotify Func + 152

7   IOKit                           0x3b2f7446 IODispatchCalloutFromCFMessage + 190

8   CoreFoundation                  0x33d1d5d8 __CFMachPortPerform + 116

9   CoreFoundation                  0x33d28170 

__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32

10  CoreFoundation                  0x33d28112 __CFRunLoopDoSource1 + 134

11  CoreFoundation                  0x33d26f94 __CFRunLoopRun + 1380

12  CoreFoundation                  0x33c99eb8 CFRunLoopRunSpecific +   352

13  CoreFoundation                  0x33c99d44 CFRunLoopRunInMode + 100

14  GraphicsServices                0x3ba972e6 GSEventRunModal + 70

15  UIKit                           0x3b5552f4 UIApplicationMain + 1116

16  DNA                             0x000dd860 main (main.m:17)

17  DNA                             0x000dd3dc start + 36

I am not using VKMapCanvas Framework but I am using Mapkit framework, when we keep moving and switching between view controllers it is crashing.For every 25 meters I am adding and removing the annotations, I searched in stackoverflow someone pointed out crashing because of annotations handling.I am unable to understand whether we are getting crash because of this.

-(void)getFieldTips:(id)response {                                                                                     
    if([response objectForKey:@"No Net"]){

    }
    else{

        [self removeTipAnnotations];
        [fieldTipsMArray removeAllObjects];
        fieldTipsMArray = [response objectForKey:@"data"];
        if ([fieldTipsMArray count]) {

            [self addFieldtipsToRoute:fieldTipsMArray];

        }
    }
}

- (void)removeTipAnnotations {

    NSMutableArray *locs = [[NSMutableArray alloc] init];

    for (id <MKAnnotation> annot in [self.theMapView annotations])
    {
        if ( [annot isKindOfClass:[ MKUserLocation class]] ) {

        }
        else if([annot.title isEqualToString:@"tip"]) {
            [locs addObject:annot];
        }

    }

    [self.theMapView removeAnnotations:locs];
    locs = nil;
}

- (void)addFieldtipsToRoute: (NSMutableArray *)fieldTipsMutableArray{

    [fieldTipsMutableArray enumerateObjectsUsingBlock:^(id fieldTipsObjectFromService, NSUInteger fieldTipsIndex, BOOL *stop) {

        fieldTipsObjectFromService = [fieldTipsMArray objectAtIndex:fieldTipsIndex];
        Annotation *ann = [[Annotation alloc] initWithLatitude:[[fieldTipsObjectFromService objectForKey:@"lat"] doubleValue] Longitude:[[fieldTipsObjectFromService objectForKey:@"lon"] doubleValue]];
        ann.title = @"tip";
        ann.tagForAnnotation = fieldTipsIndex;
        [self.theMapView addAnnotation:ann];
    }];
}

and Using below things for UserTracking

[self.theMapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];


- (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated
{

    dispatch_async(dispatch_get_main_queue(),^{
        if ([CLLocationManager locationServicesEnabled]) {
            if ([CLLocationManager headingAvailable]) {
                [self.theMapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:NO];
            }else{
                [self.theMapView setUserTrackingMode:MKUserTrackingModeFollow animated:NO];
            }
        }else{
            [self.theMapView setUserTrackingMode:MKUserTrackingModeNone animated:NO];
        }
    });

}
ios
iphone
objective-c
crash
mkmapview
asked on Stack Overflow Oct 23, 2013 by Anjaneyulu Battula • edited Jun 9, 2017 by Meet Doshi

1 Answer

0

It seems that VKMapCanvas loses delegate when it tries to invoke [VKMapCanvas animateToMapRegion:pitch:yaw:duration:completion:], Check for Responder before invoking the method delegate or NULL values.

if ([delegate respondsToSelector:@Selector(animateToMapRegion:pitch:yaw:duration:completion:)])
{

     [delegate animateToMapRegion:pitch:yaw:duration:completion:];//Call your method

}
answered on Stack Overflow Oct 23, 2013 by Meet • edited Jun 9, 2017 by Meet Doshi

User contributions licensed under CC BY-SA 3.0