UIImagePickerController偶尔会冻结

时间:2013-10-25 13:50:54

标签: ios objective-c unity3d uiimagepickercontroller

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

日志中没有错误,没有任何崩溃日志。应用程序继续正常运行UIImagePickerController。控制台中有很多消息似乎相关,例如“拒绝文件写入数据/私有/ 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中的一个错误,但是没有使用Unity的iOS开发人员遇到过这个问题,我想如果它存在的话,这个错误就已经修复了在4.3。

1 个答案:

答案 0 :(得分:1)

这是一个解决方法:你可以在UnityAppController.mm中静音CFRunLoopRunInMode,如下所示:

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