iOS:iPhone 11 Pro上的割炬级别 [英] iOS: Torch level on iPhone 11 Pro

查看:116
本文介绍了iOS:iPhone 11 Pro上的割炬级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AVCaptureDevice.setTorchModeOn(level)方法以可变的亮度打开手电筒。

I'm using AVCaptureDevice.setTorchModeOn(level) method to turn on the flashlight at variable brightness.

在我的旧版iPhone SE上,它工作正常-当我将级别 0 更改后,我可以清楚地看到4种不同的亮度级别到 1

On my old iPhone SE it's working fine — I can clearly see 4 different brightness levels as I change level from 0 to 1.

但是在iPhone 11 Pro上,手电筒仅在 1.0 !而且,如果离最大水平(与Control Center的手电筒相比),则为亮度。

But on the iPhone 11 Pro the flashlight turns on only when level is 1.0! And it's brightness if far from maximum level (compared to flashlight from Control Center).

我尝试使用 maxAvailableTorchLevel 常量,但结果与使用 1.0 相同。

还尝试了大于 1.0 —导致异常(按预期)。

I tried using maxAvailableTorchLevel constant, but results are the same as using 1.0.
Also tried values more than 1.0 — this results in exception (as expected).

有人也有这个问题吗?也许有一些解决方法?

Did anyone have this problem too? Maybe there are some workarounds?

推荐答案

我记得在iOS 3.x的日子里,我们没有简单的LED API 。我们必须开始一个完整的视频捕获会话。事实证明,对于iPhone 11来说,这似乎是唯一的解决方案。我很想听听其他不需要这样做的人。

I remembered that back in the iOS 3.x days we didn't have simple LED API. We had to start a full video capture session. Well it turns out that with the iPhone 11 this seems to be the only solution. I'd love to hear about others which don't require this.

这是我经过测试的解决方法。我在这里使用的是Objective C,而不是Swift,因为那是我从2009年起在这个旧应用中使用的!您可以轻松地找到Swift代码来开始视频捕获(而忽略输出,它应该可以正常工作。

This is my tested workaround. I am using Objective C here, not Swift because that's what I used in this old app from 2009! You can easily find Swift code to start video capture (and ignore the output, it should work the same.

AVCaptureSession* session = [[AVCaptureSession alloc] init];

AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
if ([session canAddInput:deviceInput]) {
    [session addInput:deviceInput];
}

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

CALayer *rootLayer = self.view.layer;
[rootLayer setMasksToBounds:YES];

CGRect frame = self.view.frame;
[previewLayer setFrame:frame];
[rootLayer insertSublayer:previewLayer atIndex:0];

//This is where you'd save the video with AVCaptureVideoDataOutput but of course we don't.

[session startRunning];

然后,您只需照常启动LED:

And after this you just start the LED as usual:

NSError *error = nil;

if ([inputDevice isTorchModeSupported:AVCaptureTorchModeOn])
[inputDevice setTorchModeOnWithLevel:1.0 error:&error];

这在我的iPhone 11 Pro上获得了最大的亮度。我现在正在寻找相同的解决方案,而不必使用视频捕获功能(明显地,它使用电池并且需要许可,用户可能不喜欢它。它需要详细解释)。

This gets maximum brightness on my iPhone 11 Pro. I am now looking for the same solution without having to use the video capture (which obviously uses battery AND requires a permission, which users may not like. It needs to be explained well).

这篇关于iOS:iPhone 11 Pro上的割炬级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆