Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my app crash on iOS 10 when repeatedly presenting and using UIImagePickerControllers?

An app that we developed several years ago has started crashing since iOS 10 became available. The app repeatedly presents UIImagePickerControllers to allow a user to capture several photos of a subject. After doing this 40+ times, the app crashes. This is reproducible on all of the devices we've tested on, but did not happen prior to the introduction of iOS 10. We do have the NSCameraUsageDescription and NSPhotoLibraryUsageDescription keys in the Info.plist file.

I've created a minimal sample app that demonstrates the problem. Here's the code that eventually results in the crash:

- (IBAction) cameraPressed:(id) sender {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType =  UIImagePickerControllerSourceTypeCamera;
    self.picker.delegate = self;
    self.picker.allowsEditing = NO;
    [self presentViewController:self.picker animated:YES completion:nil];
}

When the user repeatedly uses the camera button that is connected to this IBAction, it eventually starts to slow down (presentation of the picker begins taking longer), and eventually crashes (usually after 50+ uses of the camera). No crash log is produced, although when connected to Xcode, output like this appears in the console leading up to the crash:

2016-11-04 20:30:11.884984 WLPBeta[2747:275474] [MC] Invalidating cache
2016-11-04 20:30:11.890776 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:30:13.017608 WLPBeta[2747:275091] [MC] Invalidating cache
2016-11-04 20:30:13.018312 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:30:19.271720 WLPBeta[2747:276311] [MC] Invalidating cache
2016-11-04 20:30:19.279462 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:08.229294 WLPBeta[2747:278515] [MC] Invalidating cache
2016-11-04 20:32:08.273941 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:09.335711 WLPBeta[2747:278514] [MC] Invalidating cache
2016-11-04 20:32:09.342161 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:14.193376 WLPBeta[2747:278515] [MC] Invalidating cache
2016-11-04 20:32:14.213902 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:47.944657 WLPBeta[2747:275091] [MC] Invalidating cache
2016-11-04 20:32:47.972053 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:48.550934 WLPBeta[2747:279485] [MC] Invalidating cache
2016-11-04 20:32:48.575065 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:50.855308 WLPBeta[2747:279485] [MC] Invalidating cache
2016-11-04 20:32:50.856329 WLPBeta[2747:273019] [MC] Reading from public effective user settings.
2016-11-04 20:32:52.201535 WLPBeta[2747:275091] [GatekeeperXPC] Connection to assetsd was interrupted or assetsd died

I've also posted a bug report to Apple, and added it to open radar: http://www.openradar.me/radar?id=4941109843197952

Has anyone encountered this issue? Is there a fix that would allow us to move past this without recompiling the app using Xcode 8? Unfortunately we are using third party libraries that are not yet ready for Xcode 8 and the iOS 10 SDK, so we are still building the app using Xcode 7.3.1.

EDIT: here's a link to a Github repo containing an example app that can be used to demonstrate the problem.

https://github.com/lolay/ImagePickerTest

EDIT 2: If I change the code so that I allocate and initialize the picker in viewDidLoad, it still crashes after about the same number of uses of the camera button.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType =  UIImagePickerControllerSourceTypeCamera;
    self.picker.allowsEditing = NO;
}

- (IBAction) cameraPressed:(id) sender {
    [self presentViewController:self.picker animated:YES completion:nil];
}
like image 662
Greg Avatar asked Nov 09 '16 17:11

Greg


1 Answers

Your UIImagePickerController is defined as STRONG.

Please change it to weak or make sure that the object is nil before the view is destroyed.

like image 163
doxsi Avatar answered Nov 05 '22 21:11

doxsi