【问题标题】:UIImagePickerController didFinishPickingMediaWithInfo not called on 64 bit devicesUIImagePickerController didFinishPickingMediaWithInfo 未在 64 位设备上调用
【发布时间】:2014-07-28 08:35:56
【问题描述】:

我有一些适用于 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。如果您能提供任何帮助,我将不胜感激。感谢您的关注。

【问题讨论】:

    标签: ios xcode uiimagepickercontroller


    【解决方案1】:

    看起来这实际上与设备的位数无关,而是他们处理 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];
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      相关资源
      最近更新 更多