2013-10-21 66 views
1

當我在iPhone上使用UIImagePicker時,應用程序崩潰,但僅在iOS 7中崩潰。 我用下面的代碼行在iOS 7中崩潰的應用程序

picker = [[UIImagePickerController alloc] init]; 

    picker.delegate = self; 
    picker.allowsEditing = YES; 

    if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) 
    { 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } else { 
     //[self showAlertViewWithTitle:@"Sorry" message:@"Your Device Don't Have Camera"]; 
    } 

    [self presentViewController:picker animated:YES completion:nil]; 

} 

該應用在iOS 6上運行,而不是在iOS的7 我新上這個網站,請幫助。

+2

你能後你得到的例外呢? – Shaun

+1

要說清楚。它在iOS 7下運行時崩潰,並在iOS 6下運行?是的最好的方法是也從控制檯發佈錯誤消息等。 – Binarian

+0

原因:'支持的方向與應用程序沒有共同的方向,並且應該Autorotate返回YES' – Pravin

回答

1

UIImagePickerController中只有iPhone Potratin模式呈現。我發現在你的代碼多了一個錯誤,您正在使用picker.sourceType = UIImagePickerControllerSourceTypePhotoLibraryisCameraDeviceAvailable是錯的: -

你應該如下代碼: -

if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) 
    { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
       [self presentViewController:picker animated:YES completion:nil]; 
    } else { 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
       [self presentViewController:picker animated:YES completion:nil];  
    } 

,並在您的ViewController shouldAutorotate改變NO,而不是YES

+0

謝謝,nitin..its工作... – Pravin

+1

隨意接受這個答案。似乎這個答案解決了你的問題。 :) – Ganapathy

0

確定,如果是這樣的話儘量this了...

添加到您的ViewController

- (NSUInteger) supportedInterfaceOrientations 
{ 
    //Because your app is only landscape, your view controller for the view in your 
    // popover needs to support only landscape 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 
+0

我認爲這已被棄用。只有導航控制器應該有supportedInterfaceOrientations方法 – ShayanK

1

在開始寫@implementation之前ViewController.m文件下面的代碼

@interface NonRotatingUIImagePickerController : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

@end 

當你想創建圖片選擇器寫的對象下面的代碼

​​
+0

讓我知道你是否有任何問題。 – user1673099

+0

PopOverController適用於iPhone? – Pravin

+0

@Pravin,哦,對不起...等一下..我正在更新我的答案。 – user1673099