ios - 呈现 UIImagePickerController 会导致 iOS 7 崩溃

标签 ios iphone cocoa-touch ios7

我在 iOS 7 设备上显示 UIImagePickerController 时遇到问题。我使用以下代码来呈现图像选择器。

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

调用 presentViewController 后,应用程序因 exec 错误访问而崩溃。控制台报如下异常。

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

我启用了僵尸程序来查看对象是否过早释放。 Zombies 报告以下异常:

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

有什么想法吗?

编辑

这是我在启用僵尸的情况下收到的堆栈跟踪:

enter image description here

最佳答案

这是 iPad 上 iOS 7 中的一个错误。看来现在的解决方案是在打开 UIPopoverControl 之前请求对照片的许可。以下是我如何实现我的解决方案:

**// 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];
            });
        }];
    }
}**

不要忘记将 AssetsLibrary.framework 添加到您的项目中。

关于ios - 呈现 UIImagePickerController 会导致 iOS 7 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19578080/

相关文章:

ios - 具有大透明背景的CCSpriteBatchNode(cocos2d)

ios - 稍后以编程方式更改一组 NSLayoutConstraint

iphone - iPhone 应用程序上的图形

objective-c - 获取 UIWebView 屏幕上的所有文本

iphone - 自定义 CorePlot gridLineStyle

ios - 是否可以将dispatch_queue_t添加到NSMutableArray?

ios - UIView 中的 UIBezierPath 动画

iphone - 如何使用 iPhone 上的坐标打开 Google map 以获取路线

iphone - 在哪里自定义 UINavigationController 后退按钮?

iphone - 解码 UIPasteboard 上的 "Apple Web Archive pasteboard type"项目