본문 바로가기
iOS/Mac

[iOS] Camera 기능 호출하기 및 Landscape 만 지원할때 해결책

by CodeDiver 2014. 1. 9.

가로만 지원하는 App의 경우 아래의 코드와 같이 UIImagePickerController 를 이용하여 카메라 기능을 호출하면

이런 에러가 발생된다. ㅡ.ㅡ; (ios 6.0 버그라는데 6.1로 설정해도 마찬가지로 발생했다. ㅠ.ㅠ)


Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES


// 카메라 앱 구동 방법

- (void)callCamera

{

    NSLog(@"카메라 구동");

    

    UIImagePickerController* picker = [[UIImagePickerController alloc]init];

    picker.delegate = (id)self;

    picker.allowsEditing = NO;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];

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

    

    [picker release];

}


해결책!!

: 프로젝트의 배포옵션에서 전체 방향을 지원하도록 설정하거나 아래의 코드와 같

이 UIApplicationDelegate 의  .mm 파일에 아래와 같이 추가


In my case I added this to my application's delegate (I have a landscape only app), this tells the image picker it can display, because portrait is supported:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskAll;
}

And then in my view controller which happened to be a UINavigationController, I included a category with the following:

그리고.. 각 ViewController 에 아래와 같이 개별적으로 방향을 제한한다. (가로로)

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}