Skip to content

Commit

Permalink
#26 plugin is using various deprecated Cordova functions, causing war…
Browse files Browse the repository at this point in the history
…nings on iOS builds
  • Loading branch information
EddyVerbruggen committed Jun 21, 2015
1 parent b48b2a3 commit d758f42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="nl.x-services.plugins.flashlight"
version="2.0.3">
version="2.0.4">

<name>Flashlight</name>

Expand Down
19 changes: 9 additions & 10 deletions src/ios/Flashlight.m
Expand Up @@ -6,38 +6,37 @@ @implementation Flashlight

- (void)available:(CDVInvokedUrlCommand*)command {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[self deviceHasFlashlight]];
NSString *callbackId = command.callbackId;
[self writeJavascript:[pluginResult toSuccessCallbackString:callbackId]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (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];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Device is not capable of using the flashlight. Please test with flashlight.available()"];
[self writeJavascript:[pluginResult toErrorCallbackString:command.callbackId]];
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];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Device is not capable of using the flashlight. Please test with flashlight.available()"];
[self writeJavascript:[pluginResult toErrorCallbackString:command.callbackId]];
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 {
Expand Down

0 comments on commit d758f42

Please sign in to comment.