UIImagePickerController occasionally freezing up

戏子无情 提交于 2019-12-24 02:34:09

问题


I use UIImagePickerController in an Unity app. It occasionally freezes when the user presses "done". It happens most often on 3GS — about every third time — but I also had an occasional freeze on iPhone 5. This bug appears on iOS from 4.3 to 7.0. I wasn't able to determine what factors correlate with the freeze. I don't get a memory warning when I get this freeze either.

There are no errors in the log, no crashlog whatsoever. The app continues to run behind UIImagePickerController as normal. There are a lot of messages in the console that seem related, like "deny file-write-data /private/var/mobile/Media/PhotoData", but all of them can occasionally appear both when freeze is present and when everything is working alright.

Here's how I show the picker:

- (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];

}

And here're the delegate methods:

- (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.
}

I would decide that it's a bug inside the UIImagePickerController, but none of iOS developers that don't use Unity ever encountered this problem, and I would suppose that such a bug would already be fixed if it was present in 4.3.


回答1:


Thre're are a workaround: u can mute CFRunLoopRunInMode in UnityAppController.mm, like this:

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


来源:https://stackoverflow.com/questions/19591701/uiimagepickercontroller-occasionally-freezing-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!