偶尔iOS 6 MKMapView在initWithFrame中崩溃

我在苹果商店有一个应用程序,并在iOS6更新后,我有MKMapView内的百个崩溃报告。 我不能设法重现我的设备上的崩溃。 这看起来像EAGLContext的问题。 我们不在应用程序中使用OpenGL,但在不同的控制器中有多个MKMapView实例。 我在这里发现了一个类似的问题iOS 6的应用程序在EAGLContext中崩溃时显示地图,但他们使用OpenGL。

这里有回溯:

 Exception Type: SIGSEGV Exception Codes: SEGV_ACCERR at 0x1 Crashed Thread: 0 Thread 0 Crashed: 0 libGPUSupportMercury.dylib 0x00000e22 gpus_ReturnNotPermittedKillClient + 10 1 libGPUSupportMercury.dylib 0x3bccc5fb gldCreateContext + 190 2 GLEngine 0x344c2b15 gliCreateContextWithShared + 676 3 OpenGLES 0x0000491d -[EAGLContext initWithAPI:properties:] + 1433 4 OpenGLES 0x000042d7 -[EAGLContext initWithAPI:sharedWithCompute:] + 143 5 VectorKit 0x00011c81 -[VGLGPU init] + 105 6 VectorKit 0x000d4659 __24+[VGLGPU sharedInstance]_block_invoke_0 + 49 7 libdispatch.dylib 0x000014b7 _dispatch_client_callout + 23 8 libdispatch.dylib 0x000073f7 dispatch_once_f$VARIANT$mp + 43 9 VectorKit 0x00011c13 +[VGLGPU sharedInstance] + 39 10 VectorKit 0x00001db1 -[VKMainLoop updateLinkState] + 485 11 VectorKit 0x00001955 -[VKScreenCanvas _updateDisplayStatus:] + 109 12 UIKit 0x0001c371 -[UIView initWithFrame:] + 129 13 VectorKit 0x00010ca5 -[VGLScreenCanvas initWithFrame:context:] + 53 14 VectorKit 0x00010a7d -[VKScreenCanvas initWithFrame:context:] + 57 15 VectorKit 0x00010a3f -[VKScreenCanvas initWithFrame:] + 39 16 VectorKit 0x000106bd -[VKMapCanvas initWithFrame:shouldRasterize:] + 65 17 VectorKit 0x000104bb -[VKMapView initWithFrame:andGlobe:shouldRasterize:] + 647 18 MapKit 0x0000dc95 -[MKMapView _commonInitAndEnableLoading:fromIB:] + 725 19 MapKit 0x0000d811 -[MKMapView initWithFrame:] + 257 ..... 

我们遇到类似的问题,当用户的背景我们的应用程序,就像我们popup一个包含地图子视图的窗口。 由于在我们后台使用openGL调用的地图,崩溃似乎正在发生。 我们必须在如下的检查中包装地图子视图创build:

 UIApplicationState appState = [[UIApplication sharedApplication] applicationState]; if( (appState != UIApplicationStateBackground) && (appState != UIApplicationStateInactive)) { // Do map subview initialization... } else { self.attemptedToLoadMap = YES; } 

我们保存了布尔,所以如果应用程序回到前台,我们可以添加子视图进行显示。

无论何时,您都要以导致重绘操作(例如,添加注释)的方式操作地图。

http://developer.apple.com/library/ios/#qa/qa1766/_index.html

这个技术问题解决了这个问题

我们在应用程序中find了这个原因,所以我想发布解决scheme,以防其他人帮助。 我们的主视图控制器监视显示的重要位置变化,并在隐藏时停止监视。 我们的一些用户在这个屏幕上遇到了一个不相关的崩溃,这使得应用程序的监控成为现实。 当一个应用程序注册了重要的位置更改更新,iOS将实际上启动应用程序到后台,如果它没有运行告诉它的新位置。 由于我们的应用程序在第一次出现时显示地图,因此导致了崩溃。 Apple支持人员确认,运行iOS 8.x的32位设备上存在一个错误,如果在应用程序处于后台时更新MapView(或其他OpenGL上下文),则可能会导致崩溃。

我们更改了我们的代码,以便如果由于显着的位置更改而启动应用程序,我们立即停止监视并抛出exception以使应用程序崩溃。 这对用户是完全不可见的,所以他们不会注意到崩溃,并且防止了进一步的崩溃事件的发生。

 - (void)validateLaunchWithOptions:(NSDictionary *)launchOptions { if (launchOptions[@"UIApplicationLaunchOptionsLocationKey"]) { // the app was launched due to a significant location change, which is not valid and causes crashes // prevent this from happening again by disabling significant location monitoring CLLocationManager *locationManager = [[CLLocationManager alloc] init]; [locationManager stopMonitoringSignificantLocationChanges]; // intentionally crashing the app here; it is not in a good state and it needs to be prevented from // getting to any code that would re-enable significant location monitoring @throw [NSException exceptionWithName:@"com.redacted.significantLocationLaunch" reason:@"app may not be launched due to significant location changes" userInfo:@{}]; } } 

我们看到数以千计的这次崩溃,但是我们没有能够在我们的testing设备上复制它,直到我们找出原因。 如果您想复制它(并确认修复),则在您的应用程序开始监视重大的位置更改后立即发生exception。 应用程序崩溃后,去开车。 只要你的手机切换手机的iOS iOS将在后台启动应用程序,你会得到崩溃。 我们能够掌握我们的用户手机之一,并检查崩溃日志。 所有的碰撞发生在上下class途中。

我正面临类似的堆栈跟踪。 我注意到,在控制台中,它给出了有关实际问题的更多细节:在背景中不能使用GPU。 与iOS 5的地图是基于瓦片的,所以我假设没有使用GPU,但iOS 6中的新地图使用vectorgraphics,因此使用GPU。 因此,过去在后台的任何地图工作都不能成立。