UIImagePickerController在64位设备上没有调用didFinishPickingMediaWithInfo

时间:2014-06-07 00:49:18

标签: ios xcode uiimagepickercontroller

我有一些适用于iPhone 5但不适用于iPhone 5S或iPad Air的代码。我知道iPhone 5是32位而其他设备是64位,但我不知道这会如何导致我的问题。我使用相机覆盖物和标签栏上的按钮来捕捉我的照片。

我可以像这样实例化UIImagePickerController:

    UIImagePickerController *pick = [[UIImagePickerController alloc] init];
    pick.modalPresentationStyle = UIModalPresentationCurrentContext;
    pick.sourceType = UIImagePickerControllerSourceTypeCamera;
    pick.delegate = self;
    pick.wantsFullScreenLayout=YES;

    /*
     The user wants to use the camera interface. Set up our custom overlay view for the camera.
     */
    CGSize screenBounds = [UIScreen mainScreen].bounds.size;
    CGFloat cameraAspectRatio = 4.0f/3.0f;

    CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
    CGFloat scale = screenBounds.height / camViewHeight;
    pick.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
    pick.cameraViewTransform = CGAffineTransformScale(pick.cameraViewTransform, scale, scale);
    pick.showsCameraControls = NO;

    /*
     Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
     */
    [[NSBundle mainBundle] loadNibNamed:IS_IPAD ? @"OverlayView-ipad" : @"OverlayView" owner:self options:nil];
    self.overlayView.frame = pick.cameraOverlayView.frame;
    self.focusRect.layer.borderColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1.0].CGColor;
    pick.cameraOverlayView = self.overlayView;
    self.overlayView = nil;

    self.imagePickerController = pick;
    [self presentViewController:self.imagePickerController animated:YES completion:nil];

focusRect是视图上的红色矩形,用于向用户显示如何将照片居中。

我已将协议添加到我的.h文件中:UIImagePickerControllerDelegate,UINavigationControllerDelegate

我用一个IBAction调用takePicture。以下适用于32位,但不适用于64位:

- (IBAction)takePicture:(id)sender{
    [self.imagePickerController takePicture];
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; //64 bit never gets here
    //Do some stuff.
}

症状只是在没有didFinishPickingMediaWithInfo和imagePickerControllerDidCancel都没有在64位设备上执行。我的叠加层被取消,但这些方法中的代码只能在32位设备上执行。

我已经检查了其他几个问题和答案,例如this。来自不同线程的一些建议是确保将委托设置为self,向视图添加适当的协议,并确保正确键入方法名称。我相信这些都已被涵盖。

我已确认该应用程序以32位运行。由于依赖性,我将有效架构设置为" arm7 arm7s"没有arm64。我正在使用XCode5。我将非常感谢您提供的任何帮助。谢谢你的期待。

1 个答案:

答案 0 :(得分:2)

看起来这实际上与设备的位数无关,但它们如何以不同的方式处理ARC。

我通过将dismissViewControllerAnimated从takePicture移动到didFinishPickingMediaWithInfo例程来解决问题,如下所示:

- (IBAction)takePicture:(id)sender{
    [self.imagePickerController takePicture];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; //64 bit never gets here
    //Do some stuff.
    [self dismissViewControllerAnimated:YES completion:NULL];
}

我的理论是,在调用委托方法之前,对象被销毁了。