토치 모드에서 iPhone X 플래시를 실행하는 데 문제가 있습니다.터치 모드에서 iPhone X 플래시를 시작할 수 없습니다.
돌아 가기 AVCaptureDeviceTypeBuiltInTelephotoCamera 캡처 장치로 선택 : 나는
[self.captureDevice lockForConfiguration:nil];
BOOL result = [self.captureDevice setTorchModeOnWithLevel:1 error:&error];
[self.captureDevice unlockForConfiguration];
와 토치 모드로 플래시 빛을 전환하기 위해 노력하고있어
[self.captureDevice isTorchModeSupported:AVCaptureTorchModeOn]
:
com.apple.avfoundation.avcapturedevice.built-in_video:2' -
AVCaptureDeviceTypeBuiltInTelephotoCamera
와 터치 모드 가용성을 확인 후
이 호출은 성공한 것입니다. 결과 == 예, 오류 == nil. 그러나 플래시 표시등이 한 번 깜박이면 꺼집니다.
iPhone X에서이 동작을 직접 보았습니다. iPhone 8 및 iPhone 8 Plus 소유자와 동일한 동작에 대한 보고서가 있습니다. 일부 사용자는 iOS 11.1로 업데이트 한 후에이 문제가 발생한다고 말합니다. 그러나 나는 iPhone 8로 직접 재생산 할 수 없었습니다.
이 문제를 수정하거나 디버그하는 방법에 대한 아이디어가 있습니까? 내 응용 프로그램에서
전체 코드는 다음과 같습니다 :
// Retrieve the back camera
if ([AVCaptureDeviceDiscoverySession class]) {
DDLogDebug(@"Search camera with AVCaptureDeviceDiscoverySession");
AVCaptureDevice* camera =
[AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes: @[AVCaptureDeviceTypeBuiltInTelephotoCamera]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionBack].devices.firstObject;
if (!camera) {
camera = [AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes: @[AVCaptureDeviceTypeBuiltInTelephotoCamera]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionBack].devices.firstObject;
}
DDLogDebug(@"Did find %@ camera", camera);
self.captureDevice = camera;
} else {
DDLogDebug(@"Haven't found camera device with AVCaptureDeviceDiscoverySession");
}
if (!self.captureDevice) {
DDLogDebug(@"Searching at [AVCaptureDevice devices], where %lu devices available", (unsigned long)AVCaptureDevice.devices.count);
for (AVCaptureDevice *device in [AVCaptureDevice devices]) {
if ([device hasMediaType:AVMediaTypeVideo] && [device hasTorch]) {
self.captureDevice = device;
break;
}
}
}
if (!self.captureDevice) {
NSError* error = [NSError buildError:^(MRErrorBuilder *builder) {
builder.localizedDescription = NSLocalizedString(@"There is no camera devices able to measure heart rate", nil);
builder.domain = kWTCameraHeartRateMonitorError;
builder.code = 27172;
}];
DDLogError(@"%@", error);
self.session = nil;
self.handler(0, 0, error);
return NO;
}
NSError *error;
AVCaptureDeviceInput *input = [[AVCaptureDeviceInput alloc] initWithDevice:self.captureDevice
error:&error];
if (error) {
DDLogError(@"%@", error);
self.session = nil;
self.handler(0, 0, error);
return NO;
}
NSString* deviceType = [self.captureDevice respondsToSelector:@selector(deviceType)] ? self.captureDevice.deviceType : @"Unknown";
DDLogDebug(@"Configurating camera '%@'/'%@' - %@ id %@ at %ld connected: %@", self.captureDevice.localizedName, self.captureDevice.modelID, deviceType, self.captureDevice.uniqueID, (long)self.captureDevice.position, [email protected]"YES":@"NO");
self.session = [[AVCaptureSession alloc] init];
NSString* preset = [self.session canSetSessionPreset:AVCaptureSessionPresetLow] ? AVCaptureSessionPresetLow : nil;
if (preset) {
self.session.sessionPreset = preset;
}
[self.session beginConfiguration];
[self.session addInput:input];
// Find the max frame rate we can get from the given device
AVCaptureDeviceFormat *currentFormat;
for (AVCaptureDeviceFormat *format in self.captureDevice.formats)
{
NSArray *ranges = format.videoSupportedFrameRateRanges;
AVFrameRateRange *frameRates = ranges[0];
// Find the lowest resolution format at the frame rate we want.
if (frameRates.maxFrameRate == FRAMES_PER_SECOND && (!currentFormat || (CMVideoFormatDescriptionGetDimensions(format.formatDescription).width < CMVideoFormatDescriptionGetDimensions(currentFormat.formatDescription).width && CMVideoFormatDescriptionGetDimensions(format.formatDescription).height < CMVideoFormatDescriptionGetDimensions(currentFormat.formatDescription).height)))
{
currentFormat = format;
}
}
if (![self.captureDevice isTorchModeSupported:AVCaptureTorchModeOn]) {
NSError* error = [NSError buildError:^(MRErrorBuilder *builder) {
builder.localizedDescription = NSLocalizedString(@"Torch mode is not supported for your camera", nil);
builder.domain = kWTCameraHeartRateMonitorError;
builder.code = 28633;
}];
self.session = nil;
DDLogError(@"%@", error);
self.session = nil;
self.handler(0, 0, error);
return NO;
}
// Tell the device to use the max frame rate.
[self.captureDevice lockForConfiguration:nil];
DDLogVerbose(@"Turn on tourch mode with level 0.5");
self.captureDevice.flashMode = AVCaptureFlashModeOff;
BOOL result = [self.captureDevice setTorchModeOnWithLevel:0.5 error:&error];
if (!result) {
DDLogError(@"%@", error);
self.session = nil;
self.handler(0, 0, error);
return NO;
}
[self.captureDevice setFocusMode:AVCaptureFocusModeLocked];
[self.captureDevice setFocusModeLockedWithLensPosition:1.0
completionHandler:nil];
self.captureDevice.activeFormat = currentFormat;
self.captureDevice.activeVideoMinFrameDuration = CMTimeMake(1, FRAMES_PER_SECOND);
self.captureDevice.activeVideoMaxFrameDuration = CMTimeMake(1, FRAMES_PER_SECOND);
[self.captureDevice unlockForConfiguration];
// Set the output
AVCaptureVideoDataOutput* videoOutput = [AVCaptureVideoDataOutput new];
// create a queue to run the capture on
dispatch_queue_t captureQueue=dispatch_queue_create("catpureQueue", DISPATCH_QUEUE_SERIAL);
// setup our delegate
[videoOutput setSampleBufferDelegate:self queue:captureQueue];
// configure the pixel format
videoOutput.videoSettings = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)};
videoOutput.alwaysDiscardsLateVideoFrames = NO;
[self.session addOutput:videoOutput];
if (debugPath) {
NSError* error;
[[NSFileManager defaultManager] removeItemAtPath:debugPath
error:nil];
BOOL result =
[[NSFileManager defaultManager] createDirectoryAtPath:debugPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (result) {
[self setupDebugRecordAt:debugPath withFormat:currentFormat];
} else {
DDLogError(@"%@", error);
}
const char* path = [debugPath cStringUsingEncoding:NSUTF8StringEncoding];
self.filter->setDebugPath(path);
}
// Start the video session
[self.session commitConfiguration];
self.frameNumber = 0;
[self.assetWriter startWriting];
[self.assetWriter startSessionAtSourceTime:kCMTimeZero];
[self.session startRunning];
나는 비슷한 문제를 가지고 있지만 아이폰 8 아이폰 OS 11.1.1에. 내 사용자 중 일부는 버그를보고하지만, 나는 iPhone 8 또는 X를 소유하고 있지 않기 때문에 해결하기가 매우 어렵습니다. 해결책을 찾으면 업데이트하십시오. – DzungPV
안녕하세요, @ DzungPV. 내 프로젝트에서이 문제를 해결했습니다. 아래에서 내 솔루션을 읽으십시오. 희망이 당신을 도울 것입니다. – lazarev