Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Feature: Flashlight option (iOS)? #36

Closed
uofmmike opened this issue Jul 21, 2015 · 11 comments
Closed

Feature: Flashlight option (iOS)? #36

uofmmike opened this issue Jul 21, 2015 · 11 comments
Milestone

Comments

@uofmmike
Copy link

I've had some luck flicking the flashlight on in JS before launching the barcode scanner, and I've seen great results, is there a way we can add a button on the bottom left side to toggle the flashlight on/off from native code?

Looks like adding in functions from @EddyVerbruggen 's file would do the trick:

https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin/blob/master/src/ios/Flashlight.m

- (void)switchOn:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult;
    if ([self deviceHasFlashlight]) {
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        [device lockForConfiguration:nil];
        [device setTorchMode:AVCaptureTorchModeOn];
        [device setFlashMode:AVCaptureFlashModeOn];
        [device unlockForConfiguration];
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    } else {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Device is not capable of using the flashlight. Please test with flashlight.available()"];
    }
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)switchOff:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult;
    if ([self deviceHasFlashlight]) {
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        [device lockForConfiguration:nil];
        [device setTorchMode:AVCaptureTorchModeOff];
        [device setFlashMode:AVCaptureFlashModeOff];
        [device unlockForConfiguration];
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    } else {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Device is not capable of using the flashlight. Please test with flashlight.available()"];
    }
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

-(BOOL)deviceHasFlashlight {
    if (NSClassFromString(@"AVCaptureDevice")) {
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        return [device hasTorch] && [device hasFlash];
    }
    return false;
}
@hirbod
Copy link

hirbod commented Jul 31, 2015

+1

@simonpapworth6742
Copy link

+1

@lordgreg
Copy link

+1

(until then, I'll use https://github.com/tjwoon/csZBar)

@lyurko
Copy link

lyurko commented Jul 12, 2016

+1

1 similar comment
@vladpke
Copy link

vladpke commented Nov 1, 2016

+1

@EddyVerbruggen EddyVerbruggen added this to the 6.0.4 milestone Dec 4, 2016
@EddyVerbruggen
Copy link
Collaborator

Landed in 6.0.4 on both iOS and Android. Just pass in showTorchButton : true as an option of the scan function.

@douglasevaristo
Copy link

douglasevaristo commented Feb 1, 2017

"Landed in 6.0.4 on both iOS and Android. Just pass in showTorchButton : true as an option of the scan function." This don't work anymore 👎

@EddyVerbruggen
Copy link
Collaborator

@douglasevaristo Instead of the 😕 and 👎 can you please share what platform you're using, what problem you have exactly, how you're using the plugin, and how you're building it?

@kmukku
Copy link

kmukku commented Feb 27, 2017

Hi. I can confirm that the torch button is not showing up. Flip button does show up.
I'm using ionic lab + ionic view to debug the app on iPhone 7 10.2.1 (14D27).

@jcesarmobile
Copy link
Collaborator

ionic view is an app that might not have latest version of the plugin, run your app instead of using ionic view

@lock
Copy link

lock bot commented Jun 8, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests