UIImagePickerController偶尔会冻结

我在Unity应用程序中使用UIImagePickerController 。 当用户按下“完成”时它偶尔会冻结。 它经常发生在3GS上 – 大约每三次 – 但我也偶尔在iPhone 5上冻结。这个错误出现在iOS 4.3到7.0。 我无法确定哪些因素与冻结相关。 当我得到这个冻结时,我也没有得到记忆警告。

日志中没有错误,没有crashlog。 正常情况下,应用程序继续在UIImagePickerController后面运行。 在控制台中有很多看起来相关的消息,比如“deny file-write-data / private / var / mobile / Media / PhotoData”,但是当冻结出现时以及一切正在工作时,它们偶尔都会出现好的。

以下是我如何显示选取器:

 - (void)showPicker:(UIImagePickerControllerSourceType)type { imgPicker = [[[CustomPhotoPicker alloc] init] autorelease]; imgPicker.delegate = self; imgPicker.sourceType = type; imgPicker.allowsEditing = _pickerAllowsEditing; // wrap and show the modal [self showViewControllerModallyInWrapper:imgPicker]; } 

这里是委托方法:

 - (void)imagePickerController:(UIImagePickerController*)imgPicker didFinishPickingMediaWithInfo:(NSDictionary*)info { NSLog( @"imagePickerController didFinishPickingMediaWithInfo"); // If the freeze is present, this method isn't called } - (void)imagePickerController:(UIImagePickerController *)imgPicker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { NSLog( @"imagePickerController didFinishPickingImage"); // Tried to use deprecated callback. If the freeze is present, this method isn't called either. } 

我认为这是UIImagePickerController内部的一个bug,但是没有任何一个iOS开发者没有遇到过这个问题,而且我会假设这个bug在4.3中已经被修复了。

这是一个解决方法:你可以在UnityAppController.mm中静音CFRunLoopRunInMode,就像这样:

 - (void)repaintDisplayLink { [_displayLink setPaused: YES]; { static const CFStringRef kTrackingRunLoopMode = CFStringRef(UITrackingRunLoopMode); if (![EtceteraManager picking]) { while (CFRunLoopRunInMode(kTrackingRunLoopMode, kInputProcessingTime, TRUE) == kCFRunLoopRunHandledSource) ; } } }