iOS Torch level on iPhone 11 Pro

0 votes
I'm using the AVCaptureDevice.setTorchModeOn(level) method to turn on the flashlight with adjustable brightness.

It functions properly on my outdated iPhone SE; as I move from level 0 to level 1, I can plainly see the four distinct brightness levels.

However, the iPhone 11 Pro's flashlight doesn't activate until level 1.0! And while not at its brightest, it is still visible (compared to a flashlight from Control Center).

Although I used the maxAvailableTorchLevel constant, the outcomes were the same as when I used 1.0.
Additionally, attempted values greater than 1.0 produce an error (as expected).

Did anyone else experience this issue? Perhaps there are some solutions?
Sep 27, 2022 in IOS by Soham
• 9,710 points
630 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I recalled that there was no straightforward LED API back when iOS 3.x was in use. A whole video capture session had to be started. It turns out that this is the only option for the iPhone 11; however. If you know of any that don't call for this, please let me know.

This is the fix I've tried. Because I used Objective C rather than Swift in this older project from 2009, I'm utilising it here. You can quickly locate Swift code to begin video capturing (ignore the output; it should still function properly).

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];

And after this you just start the LED as usual:

NSError *error = nil;

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

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).

answered Sep 28, 2022 by Rahul
• 9,680 points

edited 5 days ago

Related Questions In IOS

0 votes
1 answer

what font face of clock on lock screen of iPhone (iOS 9)?

San Francisco is the default font in ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
1,419 views
0 votes
0 answers

How to access and read a file on a USB drive from IOS? (Connected via OTG cable to iPhone)

Can I access a text file on ...READ MORE

Nov 7, 2022 in IOS by Soham
• 9,710 points
662 views
0 votes
1 answer

HTTP live streaming server on iPhone

AZ TESTING FOR QA READ MORE

answered Oct 4, 2022 in IOS by anonymous

edited 5 days ago 1,032 views
0 votes
1 answer

Xcode 12.4 “Unsupported OS version” after iPhone iOS update 14.7

This may only be a short-term fix, ...READ MORE

answered Sep 21, 2022 in IOS by Rahul
• 9,680 points
1,487 views
0 votes
1 answer

Is it possible to run .APK/Android apps on iPad/iPhone devices?

It is not possible to run Android ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
4,809 views
0 votes
1 answer

How is a rounded rect view with transparency done on iphone?

view.layer.cornerRadius = radius; The difficult technique is to ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
1,155 views
0 votes
0 answers

iOS: Torch level on iPhone 11 Pro

I'm using AVCaptureDevice.setTorchModeOn(level) method to turn on the flashlight ...READ MORE

Nov 17, 2022 in Mobile Development by gaurav
• 23,260 points
562 views
0 votes
0 answers

iPhone system font

What is the name of the default ...READ MORE

May 16, 2022 in Others by Kichu
• 19,040 points
566 views
0 votes
1 answer

How to get landmarks from current location using google map in iphone?

You can achieve this by saving several ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
609 views
0 votes
1 answer

iPhone system font

The iPhone system interface uses Helvetica or ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
1,533 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP