停止MKMapKit位置服务时出现定期崩溃

时间:2012-09-17 22:53:46

标签: mkmapview

在applicationDidEnterBackground方法中停止MKMapView位置服务时,我很少遇到崩溃。 (我这样做是为了确保当应用在后台时我的应用不使用位置服务。)

导致崩溃的代码如下所示:

- (void)MyAppDelegate applicationDidEnterBackground:(UIApplication *app) {
     [self.baseAppViewController stopUserTracking];
}

stopUserTracking方法执行以下操作:

-(void)stopUserTracking {
    [baseAppViewController.mapView setUserTrackingMode:MKUserTrackingModeNone];
    [baseAppViewController.mapView setShowsUserLocation:NO];
}

请注意,应用程序永远不会发布baseAppViewController;也不是mapView。 baseAppViewController是其mapView的委托。代表从未设置为nil。

这是堆栈跟踪,以对MKNormalizedPointForLayer的调用结束。我在其他地方读过MKNormalizedPointForLayer可能是由于无效的注释latlng(http://stackoverflow.com/questions/9766272/error-in-main-thread-mknormalizedpointforlayer)。但是我怀疑我的应用程序就是这种情况:我试图有目的地添加带有无效lat / lng的注释,并且不会出现此错误。由于MKTilesRequireGoogleLegalNotices调用而发生这种事实是有趣的,但完全令人费解。有什么想法吗?

Thread 0 Crashed:
0   MapKit                              0x32b5de94 MKNormalizedPointForLayer + 28043
1   MapKit                              0x32b5dd8f MKNormalizedPointForLayer + 27782
2   MapKit                              0x32b5dca3 MKNormalizedPointForLayer + 27546
3   MapKit                              0x32b6b901 MKTilesRequireGoogleLegalNotices + 44500
4   MapKit                              0x32b69eed MKTilesRequireGoogleLegalNotices + 37824
5   MapKit                              0x32b50673 MKTileSupportsTileSetStyle + 15378
6   MyApp                           0x00040061 -[BaseAppViewController stopUserTracking] (BaseAppViewController.m:785)
7   MyApp                           0x0001e3c9 -[MyAppDelegate applicationDidEnterBackground:] (MyAppDelegate.m:325)
8   UIKit                               0x334fd235 -[UIApplication _handleApplicationSuspend:eventInfo:] + 760
9   UIKit                               0x3348deff -[UIApplication handleEvent:withNewEvent:] + 2094
10  UIKit                               0x3348d567 -[UIApplication sendEvent:] + 54
11  MyApp                           0x000fcb41 -[UIApplication(HMCustom) customSendEvent:] + 85
12  UIKit                               0x3348cf3b _UIApplicationHandleEvent + 5826
13  GraphicsServices                    0x3764c22b PurpleEventCallback + 882
14  CoreFoundation                      0x35a2d523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
15  CoreFoundation                      0x35a2d4c5 __CFRunLoopDoSource1 + 140
16  CoreFoundation                      0x35a2c313 __CFRunLoopRun + 1370
17  CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
18  CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
19  GraphicsServices                    0x3764b439 GSEventRunModal + 136
20  UIKit                               0x334bbcd5 UIApplicationMain + 1080
21  MyApp                           0x000026d3 main (main.m:27)

Thread 1:
0   libsystem_kernel.dylib              0x362ff3a8 kevent + 24
1   libdispatch.dylib                   0x348e9c29 _dispatch_mgr_wakeup + 0

Thread 2:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   WebCore                             0x318aeca3 _ZL12RunWebThreadPv + 402
6   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 3:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   MyApp                           0x00033823 LoggerWorkerThread (LoggerClient.m:494)
6   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 4:
0   libsystem_kernel.dylib              0x3630f570 __select + 20
1   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 5:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   Foundation                          0x354e8bb9 +[NSURLConnection(Loader) _resourceLoadLoop:] + 308
6   Foundation                          0x354e8a81 -[NSThread main] + 72
7   Foundation                          0x3557c591 __NSThread__main__ + 1048
8   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 6:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   MapKit                              0x32b4de1d MKTileSupportsTileSetStyle + 5052
6   Foundation                          0x354e8a81 -[NSThread main] + 72
7   Foundation                          0x3557c591 __NSThread__main__ + 1048
8   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 7:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   MyApp                           0x0007e78b +[ASIHTTPRequest runRequests] + 171
6   Foundation                          0x354e8a81 -[NSThread main] + 72
7   Foundation                          0x3557c591 __NSThread__main__ + 1048
8   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 8:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   WebCore                             0x318d80d9 _ZN7WebCoreL15runLoaderThreadEPv + 128
6   libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 9:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 10:
0   libsystem_c.dylib                   0x32e16cc8 start_wqthread + 0

Thread 11:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 12:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 13:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 14:
0   libsystem_kernel.dylib              0x362ff004 mach_msg_trap + 20
1   CoreFoundation                      0x35a2d3f3 __CFRunLoopServiceMachPort + 126
2   CoreFoundation                      0x35a2c12b __CFRunLoopRun + 882
3   CoreFoundation                      0x359af4a5 CFRunLoopRunSpecific + 300
4   CoreFoundation                      0x359af36d CFRunLoopRunInMode + 104
5   Foundation                          0x354dcb75 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 256
6   MyApp                           0x0011d50d +[FlurryHTTPEater sendMethod:to:body:headerFields:timeoutInterval:useWebView:] (FlurryHTTPEater.m:67)
7   MyApp                           0x00126ae9 +[FlurrySession sendSessionsToServerWithTimeout:useWebView:requestAppCircleAds:requestVideoAds:requestAppSpotAds:requestReengageAds:sendCurrentSession:] (FlurrySession.m:1053)
8   MyApp                           0x001265c7 +[FlurrySession sendSessionsToServerForAppCircle] (FlurrySession.m:1016)
9   Foundation                          0x354e8a81 -[NSThread main] + 72
10  Foundation                          0x3557c591 __NSThread__main__ + 1048
11  libsystem_c.dylib                   0x32e1c735 _pthread_start + 320

Thread 15:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 16:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 17:
0   libsystem_kernel.dylib              0x3630fcd4 __workq_kernreturn + 8

Thread 0 crashed with ARM Thread State:
    r0: 0x00000000     r1: 0x00000000     r2: 0x00000000     r3: 0x41a00000 
    r4: 0x003b3520     r5: 0x003b3520     r6: 0xfffffffc     r7: 0x2fea761c 
    r8: 0x3f01fae8     r9: 0x00000000    r10: 0x0eaec170    r11: 0x3f485f10 
    ip: 0xbff00000     sp: 0x2fea7610     lr: 0x32b548ef     pc: 0x32b5de94 
  cpsr: 0x20080030 

Binary Images:
  (truncated)

1 个答案:

答案 0 :(得分:0)

我并非100%确定它可能是那样,但您的问题可能来自“委托”问题。 尝试在方法stopUserTracking中调用此行:

baseAppViewController.mapView.delegate = nil;

这样可以防止地图向您的视图控制器的解除分配的实例发送信息,从而导致您的应用崩溃。 当您的应用从后台重新加载时(可能在viewWillAppear中),请务必添加此行,以确保您的应用正常运行:

 baseAppViewController.mapView.delegate = self;

如果它无法解决您的问题,请尝试在配置选项中启用“Zombie对象”,如下所述:How do I set up NSZombieEnabled in Xcode 4?它有助于了解在应用中发生此类意外错误时发生的情况。