在我的 IOS 应用程序中,我将 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];
}];
}
并使用以下内容进行用户跟踪
[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];
}
});
}