Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a camera flash is available on an iOS device

Tags:

ios

iphone

Overall my app works on all iOS device however I have a feature that only works on iPhone 4's therefore if the user does not have an iPhone 4 I'd like to display an alert letting them know that this feature won't work on their device?

How can I do that?

I'm trying to check if the device has the camera-flash

like image 749
Christian Gossain Avatar asked Dec 12 '10 21:12

Christian Gossain


People also ask

Does my iPhone camera have a flash?

Your iPhone's Camera app has a built-in flash for taking photos in low-light situations. But like any compact digital camera in which the flash is positioned very close to the lens, you might not love the results you get when you use it.

Why is my flash not working IOS?

Your iPhone Flashlight may refuse to work because probably it is stuck in the camera app. If this is the case you should go to the Camera app and on the video, section click on the icon for flash. Set the flash on then off to ensure that it is completely closed then try opening the flashlight again on your iPhone.

How do I know if my camera has flash?

This will look like a little bolt of lightning, and will give you direct access to the camera's flash control. Here's an example of what this flash button looks like on the back of a Sony compact camera. The flash symbol is universal, so just look for the lightning bolt icon on your back of your camera.


4 Answers

If you aren't using UIImagePicker:

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
BOOL hasFlash = [device hasFlash];

There is also a [device hasTorch] if you need it.

like image 194
Dunja Lalic Avatar answered Nov 06 '22 07:11

Dunja Lalic


Have you tried the various UIDevice methods? That said, there's most likely an easier way, depending on what specific feature your optional functionality requires, but without knowing what this is it's hard to give a concrete example.

N.B.: I'd also recommend not presuming a feature set based on the detected device itself for reasons of future compatibility.

UPDATE

In terms of the camera flash, I know you can use the UIImagePickerController's isFlashAvailableForCameraDevice: method. (You'll probably want to call this after first verifying the existance of a camera via the isCameraDeviceAvailable: method.)

like image 44
John Parker Avatar answered Nov 06 '22 06:11

John Parker


You don't need to know what device you're running on, check to see if the feature you want to use is available and display an alert if it isn't.

If you let us know what specific feature you're looking for, we can help with the specific way to check for that feature.

Though, my own advice here, popping up a dialog box that says, "If you had a newer phone, you'd be able to do this!" is really just rubbing your user's face in the fact that they've got an older phone, now isn't it? A better way to handle it would be to 1) make it clear in your AppStore page that certain features won't be available on non iPhone 4 phones and 2) make your app's behavior degrade gracefully on non iPhone 4s.

like image 3
kubi Avatar answered Nov 06 '22 06:11

kubi


For swift 4.0

let device = AVCaptureDevice.default(for: .video)
         var hasFlash: Bool! = false
         hasFlash = device?.hasFlash
like image 1
Shehbaz Khan Avatar answered Nov 06 '22 06:11

Shehbaz Khan