3

iOS-app가 최소화되었을 때 카메라에서 사진을 찍는 방법은 무엇입니까?
(즉, 후 applicationDidEnterBackground:/applicationWillResignActive:)iOS-app 캡처 사진이 어떻게 최소화 되었습니까?

AppDelegate.m : (thank you link)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    //To make the code block asynchronous 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     //### background task starts 
     NSLog(@"Running in the background\n"); 
     while(TRUE) 
     { 
      printf("Called"); //////Work fine 

      [self.window.rootViewController captureNow]; /////Capture picture! 

      [NSThread sleepForTimeInterval: 10.0]; //wait for 10 sec 
     } 
    }); 

    return YES; 
} 

OurViewController.m : (thank you link)

-(IBAction)captureNow { 

    AVCaptureConnection *videoConnection = nil; 
    for (AVCaptureConnection *connection in _stillImageOutput.connections) 
    { 
     for (AVCaptureInputPort *port in [connection inputPorts]) 
     { 
      if ([[port mediaType] isEqual:AVMediaTypeVideo]) 
      { 
       videoConnection = connection; 
       break; 
      } 
     } 
     if (videoConnection) 
     { 
      break; 
     } 
    } 

    NSLog(@"about to request a capture from: %@", _stillImageOutput); 
    [_stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
    { 
     CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL); 

     if (error) 
     { 
      NSLog(@"ERROR = %@", error); ///// Error! 
     } 

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; ////SIGABRT, cause imageSampleBuffer is nil 
     UIImage *image = [[UIImage alloc] initWithData:imageData]; 

     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 

     [image release]; 
    }]; 
} 

이 코드는 잘 작동, 응용 프로그램이 활성 상태 일 때. 그러나 앱이 최소화되면 오류 (SIGABRT)를 취하십시오.

어쩌면 다른 도서관이 그것을 할 여유가 있습니까?

+0

백그라운드에서 카메라를 사용할 수 없습니다. 개인용 API를 사용하는 탈옥 애플 리케이션을위한 방법이있을 수 있지만 앱 스토어 승인을 얻지는 못할 것입니다. –

+0

http://stackoverflow.com/questions/11090184/how-does-the-ios-app-display-recorder-record-the-screen-without-using-private-ap – vikingosegundo

답변

5

개인 정보 보호를 위해 앱이 배경에있을 때 카메라에 액세스 할 수 없습니다.

왜?

글쎄, 나는 당신이 그것을 기쁘게 생각합니다. 이야기 시간!


밥 (Bob)은 NSA에서 일하는 사람으로 상어를 통제하는 비밀 비밀 원숭이를 개발하는 사람입니다. 왜? 그는 말할 수 없다.

밥 어느 날 자신의 아이폰에 응용 프로그램을 다운로드 한 존의 비밀 Stealer. Bob은 앱 제목을 읽지 않습니다.

밥은 매우 건 망한 사람이므로 언젠가는 전화기를 직장 밖의 사물함에두고가는 것을 잊었습니다. 슈퍼 비밀의 상어 제조법을 지키면서 그는 주머니에 전화기를 느꼈고 그것을 꺼냈다. 그가 텍스트를 가지고 있기 때문에 그것은 윙윙 거리다.

그 순간에 John 's Secret Stealer은 Bob의 휴대 전화의 후면 카메라를 사용하여 사진을 찍어 John의 서버로 전송하고 Bob은 결코 알지 못했습니다.

그 다음날 전 세계가 상어를 통제하는 비밀 프로젝트에 대해 알고있었습니다.


이것은 극단적 인 예이지만 규칙의 원칙입니다. Apple의 정책은 Bob의 상황을 피하기 위해 사용자가 항상 통제 할 수 있다는 것입니다.

+1

플롯 트위스트! 밥은 이미 존을 알고 거리에서 그를 보았습니다. –

관련 문제