나는 프론트 카메라를 사용하여 사용자에게 '거울'을 보여주는 '거울'과 같은 뷰를 내 앱에서 만들었습니다. 내가 겪고있는 문제는 몇 주 후에이 코드를 건드리지 않았다는 것입니다.하지만 지금은 다시 테스트하고 작동하지 않습니다. 코드는 이전과 동일하며 오류가 발생하지 않으며 스토리 보드의보기는 이전과 완전히 동일합니다. 나는 무슨 일이 일어나고 있는지 전혀 모른다. 그래서 나는이 웹 사이트가 도움이되기를 바랬다. 이 코드는 때때로 작동하지만 다른 코드는 작동하지 않는 이유는 무엇입니까?
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
//If the front camera is available, show the camera
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureOutput *output = [[AVCaptureStillImageOutput alloc] init];
[session addOutput:output];
//Setup camera input
NSArray *possibleDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
//You could check for front or back camera here, but for simplicity just grab the first device
AVCaptureDevice *device = [possibleDevices objectAtIndex:1];
NSError *error = nil;
// create an input and add it to the session
AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; //Handle errors
//set the session preset
session.sessionPreset = AVCaptureSessionPresetHigh; //Or other preset supported by the input device
[session addInput:input];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
//Now you can add this layer to a view of your view controller
[cameraView.layer addSublayer:previewLayer];
previewLayer.frame = self.cameraView.bounds;
[session startRunning];
if ([session isRunning]) {
NSLog(@"The session is running");
}
if ([session isInterrupted]) {
NSLog(@"The session has been interupted");
}
} else {
//Tell the user they don't have a front facing camera
}
고급에 감사 :
여기 내 코드입니다.
나는 그걸 또한했고, 여전히 아무것도 보이지 않습니다. 너는 무엇을 시험하고 있니? 그것이 iOS 6 GM를 달리게 할 수 있으면 나는 달리게한다. –
또한 'cameraView'도 확인했는데 UIView 일뿐입니다. 나는 또한 내 코드를 깨뜨렸고 전체 코드를 거쳐서 무언가를 잊어 버리고있는 것처럼 보입니다 - 나는 단지 무엇을 모르겠습니다. –
GM을 실행하는 iPhone 4s에서 질문의 코드를 실행하여 정상적으로 작동했습니다. – mttrb