cordova-plugin-mserviceinterface-2.0 1.0.48 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-plugin-mserviceinterface-2.0"
5
- version="1.0.48">
5
+ version="1.0.49">
6
6
  <name>mserviceinterface-2.0</name>
7
7
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
8
8
  <author>selfservit@gmail.com</author>
@@ -36,6 +36,8 @@
36
36
  NSString *clientUrl;
37
37
  NSString *deviceID;
38
38
  NSString *appInfoCaller;
39
+ NSString *imageAttachmentInd;
40
+ NSString *imageDestinationPath;
39
41
  @protected BOOL _isLocked;
40
42
  UIInterfaceOrientation _lastOrientation;
41
43
  }
@@ -1437,6 +1437,9 @@
1437
1437
  }
1438
1438
 
1439
1439
  - (void)CaptureImageFromCamera:(CDVInvokedUrlCommand*)command {
1440
+ NSMutableDictionary *inputObject = [[command arguments] objectAtIndex:0];
1441
+ imageAttachmentInd = inputObject[@"attachmentInd"];
1442
+ imageDestinationPath = inputObject[@"destinationPath"];
1440
1443
  cameraOpen= [[UIImagePickerController alloc] init];
1441
1444
  if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
1442
1445
  return;
@@ -1455,6 +1458,9 @@
1455
1458
  }
1456
1459
 
1457
1460
  - (void)PickImageFromGallery:(CDVInvokedUrlCommand*)command {
1461
+ NSMutableDictionary *inputObject = [[command arguments] objectAtIndex:0];
1462
+ imageAttachmentInd = inputObject[@"attachmentInd"];
1463
+ imageDestinationPath = inputObject[@"destinationPath"];
1458
1464
  imagePicker= [[UIImagePickerController alloc] init];
1459
1465
  /*if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
1460
1466
  return;
@@ -1991,7 +1997,7 @@
1991
1997
  }
1992
1998
  NSDate *now = [NSDate date];
1993
1999
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
1994
- dateFormatter.dateFormat = @"yyyyMMdd_HHmm-ss";
2000
+ dateFormatter.dateFormat = @"yyyyMMddHHmmss";
1995
2001
  [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
1996
2002
  NSString *gmtTime = [dateFormatter stringFromDate:now];
1997
2003
  NSString *destination = [NSString stringWithFormat:@"%@/%@.jpg", dest, gmtTime];
@@ -2014,26 +2020,113 @@
2014
2020
  NSLog(@"refURL : %@", refURL);
2015
2021
  ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2016
2022
  [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2017
- } else if ([picker isEqual: cameraOpen] || [picker isEqual:imagePicker]) {
2018
- //if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
2023
+ } else if ([picker isEqual: cameraOpen]) {
2024
+ if ([imageAttachmentInd isEqualToString:@"true"]) {
2025
+ //if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
2026
+ [picker dismissViewControllerAnimated:YES completion:nil];
2027
+ // } else {
2028
+ // [popover dismissPopoverAnimated:YES];
2029
+ // }
2030
+ UIImageView *ivPickedImage = [[UIImageView alloc] init];
2031
+ ivPickedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
2032
+ NSURL *refURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
2033
+ // define the block to call when we get the asset based on the url (below)
2034
+ ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {
2035
+ UIImage *image = ivPickedImage.image;
2036
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
2037
+ NSString *directory = [paths objectAtIndex:0];
2038
+ NSString* appRootPath = [directory stringByAppendingPathComponent:[self GetAppName]];
2039
+ NSString *imagesFolderPath = [appRootPath stringByAppendingPathComponent:imageDestinationPath];
2040
+ if (![[NSFileManager defaultManager] fileExistsAtPath:imagesFolderPath]){
2041
+ [[NSFileManager defaultManager] createDirectoryAtPath:imagesFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
2042
+ }
2043
+ NSDateFormatter *dateFormatter = [self getCurrentDateTime];
2044
+ [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
2045
+ NSString *fileName = [NSString stringWithFormat:@"%@.png", [dateFormatter stringFromDate:[NSDate date]]];
2046
+ NSString* imageSavedPath = [imagesFolderPath stringByAppendingPathComponent:fileName];
2047
+ NSData* imageData = UIImageJPEGRepresentation(image, 0.3);
2048
+ [imageData writeToFile:imageSavedPath atomically:YES];
2049
+ long imgSize = imageData.length;
2050
+ NSString *strImageSize = [NSString stringWithFormat:@"%ld", imgSize];
2051
+ NSString *extension = [[NSString stringWithFormat:@".%@",[imageSavedPath pathExtension]] lowercaseString];
2052
+ NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
2053
+ [dict setValue:[imageSavedPath stringByDeletingLastPathComponent] forKey:@"filePath"];
2054
+ [dict setValue:[imageSavedPath lastPathComponent] forKey:@"fileName"];
2055
+ [dict setValue:strImageSize forKey:@"fileSize"];
2056
+ [dict setValue:extension forKey:@"fileExtension"];
2057
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict];
2058
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackIdForImagePicker];
2059
+ };
2060
+ ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2061
+ [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2062
+ } else {
2019
2063
  [picker dismissViewControllerAnimated:YES completion:nil];
2020
- // } else {
2021
- // [popover dismissPopoverAnimated:YES];
2022
- // }
2023
- UIImageView *ivPickedImage = [[UIImageView alloc] init];
2024
- ivPickedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
2025
- UIImage *finalImage = [self imageWithImage:ivPickedImage.image scaledToWidth:824.00];
2026
- NSURL *refURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
2027
- // define the block to call when we get the asset based on the url (below)
2028
- ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
2029
- {
2030
- NSData *imageData = UIImageJPEGRepresentation(finalImage, 0.1);
2031
- NSString * base64String = [imageData base64EncodedStringWithOptions:0];
2032
- CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:base64String];
2033
- [self.commandDelegate sendPluginResult:result callbackId:self.callbackIdForImagePicker];
2034
- };
2035
- ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2036
- [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2064
+ UIImageView *ivPickedImage = [[UIImageView alloc] init];
2065
+ ivPickedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
2066
+ UIImage *finalImage = [self imageWithImage:ivPickedImage.image scaledToWidth:824.00];
2067
+ NSURL *refURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
2068
+ ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
2069
+ {
2070
+ NSData *imageData = UIImageJPEGRepresentation(finalImage, 0.1);
2071
+ NSString * base64String = [imageData base64EncodedStringWithOptions:0];
2072
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:base64String];
2073
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackIdForImagePicker];
2074
+ };
2075
+ ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2076
+ [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2077
+ }
2078
+ } else if ([picker isEqual:imagePicker]) {
2079
+ if ([imageAttachmentInd isEqualToString:@"true"]) {
2080
+ UIImageView *ivPickedImage = [[UIImageView alloc] init];
2081
+ ivPickedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
2082
+ NSURL *refURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
2083
+ // define the block to call when we get the asset based on the url (below)
2084
+ ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {
2085
+ UIImage *image = ivPickedImage.image;
2086
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
2087
+ NSString *directory = [paths objectAtIndex:0];
2088
+ NSString* appRootPath = [directory stringByAppendingPathComponent:[self GetAppName]];
2089
+ NSString *imagesFolderPath = [appRootPath stringByAppendingPathComponent:imageDestinationPath];
2090
+ if (![[NSFileManager defaultManager] fileExistsAtPath:imagesFolderPath]){
2091
+ [[NSFileManager defaultManager] createDirectoryAtPath:imagesFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
2092
+ }
2093
+ NSDateFormatter *dateFormatter = [self getCurrentDateTime];
2094
+ [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
2095
+ NSString *fileName = [NSString stringWithFormat:@"%@.png", [dateFormatter stringFromDate:[NSDate date]]];
2096
+ NSString* imageSavedPath = [imagesFolderPath stringByAppendingPathComponent:fileName];
2097
+ NSData* imageData = UIImageJPEGRepresentation(image, 0.3);
2098
+ [imageData writeToFile:imageSavedPath atomically:YES];
2099
+ long imgSize = imageData.length;
2100
+ NSString *strImageSize = [NSString stringWithFormat:@"%ld", imgSize];
2101
+ NSString *extension = [[NSString stringWithFormat:@".%@",[imageSavedPath pathExtension]] lowercaseString];
2102
+ NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
2103
+ [dict setValue:[imageSavedPath stringByDeletingLastPathComponent] forKey:@"filePath"];
2104
+ [dict setValue:[imageSavedPath lastPathComponent] forKey:@"fileName"];
2105
+ [dict setValue:strImageSize forKey:@"fileSize"];
2106
+ [dict setValue:extension forKey:@"fileExtension"];
2107
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict];
2108
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackIdForImagePicker];
2109
+ };
2110
+ // get the asset library and fetch the asset based on the ref url (pass in block above)
2111
+ NSLog(@"refURL : %@", refURL);
2112
+ ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2113
+ [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2114
+ } else {
2115
+ [picker dismissViewControllerAnimated:YES completion:nil];
2116
+ UIImageView *ivPickedImage = [[UIImageView alloc] init];
2117
+ ivPickedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
2118
+ UIImage *finalImage = [self imageWithImage:ivPickedImage.image scaledToWidth:824.00];
2119
+ NSURL *refURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
2120
+ ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
2121
+ {
2122
+ NSData *imageData = UIImageJPEGRepresentation(finalImage, 0.1);
2123
+ NSString * base64String = [imageData base64EncodedStringWithOptions:0];
2124
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:base64String];
2125
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackIdForImagePicker];
2126
+ };
2127
+ ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
2128
+ [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
2129
+ }
2037
2130
  } else if ([picker isEqual:liveCamera]) {
2038
2131
  //if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
2039
2132
  [picker dismissViewControllerAnimated:YES completion:nil];