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)를 취하십시오.
어쩌면 다른 도서관이 그것을 할 여유가 있습니까?
백그라운드에서 카메라를 사용할 수 없습니다. 개인용 API를 사용하는 탈옥 애플 리케이션을위한 방법이있을 수 있지만 앱 스토어 승인을 얻지는 못할 것입니다. –
http://stackoverflow.com/questions/11090184/how-does-the-ios-app-display-recorder-record-the-screen-without-using-private-ap – vikingosegundo