Occasionally iOS 6 MKMapView crashes in initWithFrame

前端 未结 4 889
傲寒
傲寒 2020-12-13 00:35

I\'ve an app on the apple store and after the iOS6 update I\'ve got hundred of crash report within MKMapView. I cannot manage to reproduce the crash on my devic

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 01:10

    We found the cause of this in our app so I wanted to post the solution in case it would help anyone else. Our primary view controller monitors significant location changes when it is displayed and stops monitoring when it is hidden. Some number of our users experienced an unrelated crash on this screen, which left the app monitoring. When an app has registered for significant location change updates, iOS will actually launch the app into the background if it is not running to tell it about the new location. Since our app displays a map when it first comes up, this caused a crash. Apple support confirmed with us that there is a bug on 32 bit devices running iOS 8.x that may cause a crash if a MapView (or other OpenGL context) is updated while the app is in the background.

    We changed our code so that if the app is launched due to a significant location change we immediately stop monitoring and throw an exception to crash the app. This is completely invisible to the user so they do not notice the crash, and it prevents further crashes from happening.

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

    We saw thousands of this crash but were not able to duplicate it on our test devices until we figured out the cause. If you would like to duplicate it (and also confirm the fix), @throw an exception immediately after your app starts monitoring significant location changes. After the app crashes, go take a drive. As soon as your phone switches cell towers iOS will launch the app in the background and you will get the crash. We were able to get our hands on one of our users phones and inspect the crash logs. All of the crashes happened during her commute to and from work.

提交回复
热议问题