2012-12-26 4 views
1

현재, 나는 이미지 & 비디오 캡처를위한 카메라 & 비디오보기를 열려면이 코드를 사용하고 있습니다 : 그것은 잘 작동하고동적으로 반복적으로 열고 카메라 뷰

- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller 
            usingDelegate: (id <UIImagePickerControllerDelegate, 
                UINavigationControllerDelegate>) delegate 
{ 
    [optionView removeFromSuperview]; 

    if (([UIImagePickerController isSourceTypeAvailable: 
      UIImagePickerControllerSourceTypeCamera] == NO) 
     || (delegate == nil) 
     || (controller == nil)) 
     return NO; 

    if (videoModeFlag==TRUE) 
    { 
     cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; 
     cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; 
     cameraUI.allowsEditing = NO; 
     cameraUI.delegate = delegate; 
     [self presentViewController:cameraUI animated:YES completion:nil]; 
     videoModeFlag=FALSE; 
    } 
    else 
    { 
     photoclick.sourceType = UIImagePickerControllerSourceTypeCamera; 
     photoclick.delegate = self; 
     [self presentViewController:photoclick animated:YES completion:nil]; 
    } 

    return YES; 
} 

. 하지만 카메라보기를 반복해서 열려고하고 사용 단추를 클릭하면 이미지를 디렉터리에 저장하려고합니다. 이것은 내가 시도하는 것입니다 :

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
{ 
    saveFlag =TRUE; 
    [self.view addSubview:typename]; 
    image = [[info objectForKey:UIImagePickerControllerOriginalImage] copy]; 
    mediaType = [[info objectForKey: UIImagePickerControllerMediaType] copy]; 
    movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] copy]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 

     timer = [NSTimer scheduledTimerWithTimeInterval:10.0 
               target:self 
               selector: @selector(targetMethod) 
               userInfo:nil 
               repeats:YES]; 
- (void)targetMethod 
{ 

    a++;                    

     [self startCameraControllerFromViewController: self 
             usingDelegate: self]; 


    if (a==5) 
    { 
     [timer invalidate]; 
    } 
} 

그러나 카메라를 반복적으로 열 수 없습니다.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <ViewController: 0x49bab0>.' 

을 내가 타이머를 사용하고 있지 않다 때 다음이 내가 뭐하는 거지입니다 : : 여기 오류 얻을 수있다

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
{ 
    saveFlag =TRUE; 
    //[self.view addSubview:typename]; 
    image = [[info objectForKey:UIImagePickerControllerOriginalImage] copy]; 
    mediaType = [[info objectForKey: UIImagePickerControllerMediaType] copy]; 
    movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] copy]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 

    NSMutableArray *sd=[[NSMutableArray alloc]init]; 
    sd = [[getPickerData componentsSeparatedByString: @"\n--- end of page ---\n"] mutableCopy]; 
    NSLog(@"sd:%@",sd); 
    for (int i=0; i<=[sd count]; i++) 
    { 
     [self startCameraControllerFromViewController: self 
             usingDelegate: self]; 
    } 
} 

나는이 시점에서 막혔어요. 이 문제를 어떻게 해결할 수 있습니까? 고맙습니다.

답변

0

나는 ... 오류가 이미 표시되는 뷰 컨트롤러의 모달을 제시하기 위해 노력하고 있다고 생각

문제는, 당신은하지만, 카메라 뷰를 10 초마다 열려고 할 수있다 그 시점에 기존의 표시된보기가 닫히지 않으면 문제가 발생할 수 있습니다.

타이머를 사용하는 대신 선택기를 닫은 후에 다시 수동으로 표시하십시오. 이미 표시된 횟수를 추적하기 위해 인스턴스 변수를 가질 수 있습니다.

+0

자체 캡처 메서드를 호출하는 데 사용하고 있지만 문제는 동일합니다 ... – Vishal

+0

수정 된 코드를 업데이트 하시겠습니까? –

+0

내 질문을 업데이 트 ... – Vishal

관련 문제