简体   繁体   English

呈现UIImagePickerController会导致iOS 7崩溃

[英]Presenting the UIImagePickerController causes a crash on iOS 7

I'm having an issue presenting the UIImagePickerController on iOS 7 devices. 我在iOS 7设备上展示UIImagePickerController时遇到问题。 I use the following code to present the image picker. 我使用以下代码来呈现图像选择器。

UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
cameraUI.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
cameraUI.delegate = self;

[[self presentViewController:cameraUI animated:YES completion:NULL];

After the call to presentViewController, the application crashes due to an exec bad access. 在调用presentViewController之后,应用程序因执行错误访问而崩溃。 The console reports the following exceptions. 控制台报告以下异常。

[SBSAccelerometer valueRestriction]: unrecognized selector sent to instance 0x1650e360
[__NSCFNumber valueRestriction]: unrecognized selector sent to instance 0x146d0e70

I enabled zombies to see if an object is getting deallocated prematurely. 我让僵尸看到一个对象是否过早被解除分配。 Zombies reports the following exceptions: Zombies报告以下例外情况:

[NSISRestrictedToNonNegativeVariable retain]: message sent to deallocated instance 0x156f0010

Any thoughts? 有什么想法吗?

EDIT 编辑

Here is the stack trace I receive with zombies enabled: 这是我在启用僵尸时收到的堆栈跟踪:

在此输入图像描述

This is a bug in iOS 7 on iPad. 这是iPad上的iOS 7中的一个错误。 It appears the solution for now is to request permission to photos before opening the UIPopoverControl. 现在的解决方案似乎是在打开UIPopoverControl之前请求照片权限。 Here is how I implemented my solution: 以下是我实施解决方案的方法:

**// Photo Library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
    void(^blk)() =  ^() {
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        if (NIIsPad()) {
            UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:picker];
            [popover presentPopoverFromBarButtonItem:self.popoverAnchor permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        } else {
            [self.navigationController presentModalViewController:picker animated:YES];
        }
    };

    // Make sure we have permission, otherwise request it first
    ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
    ALAuthorizationStatus authStatus;
    if (IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
        authStatus = [ALAssetsLibrary authorizationStatus];
    else
        authStatus = ALAuthorizationStatusAuthorized;

    if (authStatus == ALAuthorizationStatusAuthorized) {
        blk();
    } else if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
        [[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
    } else if (authStatus == ALAuthorizationStatusNotDetermined) {
        [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
            // Catch the final iteration, ignore the rest
            if (group == nil)
                dispatch_async(dispatch_get_main_queue(), ^{
                    blk();
                });
            *stop = YES;
        } failureBlock:^(NSError *error) {
            // failure :(
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
            });
        }];
    }
}**

Don't forget to add AssetsLibrary.framework to your project. 不要忘记将AssetsLibrary.framework添加到您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM