2014-06-07 42 views
3

我有一些代碼適用於iPhone 5,但不適用於iPhone 5S或iPad Air。我知道iPhone 5是32位,其他設備是64位,但我不明白這是如何導致我的問題。我使用一個帶有一個標籤欄上的按鈕的攝像頭覆蓋捕捉我的照片。UIImagePickerController didFinishPickingMediaWithInfo在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]; 

的定焦矩形是一個紅色矩形在視圖上向用戶展示如何中心的照片。

我已經加入了協議,我.h文件中:UIImagePickerControllerDelegate,UINavigationControllerDelegate

我打電話takePicture與IBAction爲。在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.I將不勝感激您提供的任何幫助。感謝您的期待。

回答

2

看起來這實際上與設備的位數無關,但他們如何處理ARC的方式不同。

我從takePicture移動dismissViewControllerAnimated到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]; 
} 

我的理論是,對象是被破壞的委託方法可稱爲前。

相關問題