繁体   English   中英

偶尔ios MKMapView在转到其他屏幕时会崩溃并重新回到MapScreen

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

在我的IOS App中,我将Map包含的视图控制器声明为共享实例。

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

我没有使用VKMapCanvas框架,但我正在使用Mapkit框架,当我们继续移动并在视图控制器之间切换时它正在崩溃。对于每25米我添加并删除注释,我在stackoverflow中搜索有人指出由于注释处理而崩溃我无法理解我们是否因此而崩溃。

-(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];
    }];
}

并使用以下内容进行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];
        }
    });

}

似乎VKMapCanvas在尝试调用[VKMapCanvas animateToMapRegion:pitch:yaw:duration:completion:]时失去委托,在调用方法委托或NULL值之前检查Responder。

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

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM