cordova-plugin-mserviceinterface-2.0 1.0.48 → 1.0.50
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 +1 -1
- package/plugin.xml +1 -1
- package/src/android/mInterfaceService.java +98 -99
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +113 -20
package/package.json
CHANGED
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.
|
|
5
|
+
version="1.0.50">
|
|
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>
|
|
@@ -141,7 +141,20 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
141
141
|
TimerTask setQueueIntervalObj, setTimerIntervelObj;
|
|
142
142
|
Intent serviceIntent = new Intent(getApplicationContext(), mInterfaceReceiver.class);
|
|
143
143
|
serviceIntent.setAction("com.example.checkservice");
|
|
144
|
-
final PendingIntent pIntent
|
|
144
|
+
final PendingIntent pIntent;
|
|
145
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
|
146
|
+
pIntent = PendingIntent.getBroadcast(getApplicationContext(),
|
|
147
|
+
0,
|
|
148
|
+
serviceIntent,
|
|
149
|
+
PendingIntent.FLAG_IMMUTABLE);
|
|
150
|
+
}
|
|
151
|
+
else
|
|
152
|
+
{
|
|
153
|
+
pIntent = PendingIntent.getBroadcast(getApplicationContext(),
|
|
154
|
+
0,
|
|
155
|
+
serviceIntent,
|
|
156
|
+
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
157
|
+
}
|
|
145
158
|
long firstMillis = System.currentTimeMillis();
|
|
146
159
|
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
|
147
160
|
alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis,
|
|
@@ -159,19 +172,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
159
172
|
|
|
160
173
|
// App State Info Process //
|
|
161
174
|
mInterfaceUtil.validateAppStateInfo(getApplicationContext());
|
|
162
|
-
|
|
163
|
-
// **** TimeReader Interval Timer ***** //
|
|
164
|
-
setTimerIntervel = new Timer();
|
|
165
|
-
setTimerIntervelObj = new TimerTask() {
|
|
166
|
-
public void run() {
|
|
167
|
-
try {
|
|
168
|
-
timeReader();
|
|
169
|
-
} catch (Exception e) {
|
|
170
|
-
e.printStackTrace();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
setTimerIntervel.schedule(setTimerIntervelObj, 60000, 60000);
|
|
175
175
|
if (!isGooglePlayServicesAvailable()) {
|
|
176
176
|
//need to write location log file...
|
|
177
177
|
System.out.println("Play services not available..");
|
|
@@ -292,30 +292,38 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
protected void startLocationUpdates() {
|
|
295
|
-
|
|
296
|
-
if (
|
|
295
|
+
try {
|
|
296
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
297
|
+
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
297
298
|
|
|
299
|
+
}
|
|
298
300
|
}
|
|
301
|
+
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
|
|
302
|
+
} catch (Exception e) {
|
|
303
|
+
e.printStackTrace();
|
|
299
304
|
}
|
|
300
|
-
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
@Override
|
|
304
308
|
public void onLocationChanged(Location location) {
|
|
305
|
-
|
|
306
|
-
locationUpdateInd
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
309
|
+
try {
|
|
310
|
+
if (locationUpdateInd == "true") {
|
|
311
|
+
locationUpdateInd = "false";
|
|
312
|
+
mCurrentLocation = location;
|
|
313
|
+
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
|
|
314
|
+
String lat = String.valueOf(mCurrentLocation.getLatitude());
|
|
315
|
+
String lng = String.valueOf(mCurrentLocation.getLongitude());
|
|
316
|
+
if (!isLocationDuplicate(lat, lng)) {
|
|
317
|
+
new UpdateLocation(lat, lng).execute("");
|
|
318
|
+
if (isConnected()) {
|
|
319
|
+
new SendLocation().execute();
|
|
320
|
+
}
|
|
315
321
|
}
|
|
322
|
+
String string = ("Latitude : " + lat + "Longitude : " + lng + "\n");
|
|
323
|
+
System.out.println(string);
|
|
316
324
|
}
|
|
317
|
-
|
|
318
|
-
|
|
325
|
+
} catch (Exception e) {
|
|
326
|
+
e.printStackTrace();
|
|
319
327
|
}
|
|
320
328
|
}
|
|
321
329
|
|
|
@@ -353,8 +361,12 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
353
361
|
|
|
354
362
|
@Override
|
|
355
363
|
public void onConnected(@Nullable Bundle bundle) {
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
try {
|
|
365
|
+
if (mGoogleApiClient.isConnected()) {
|
|
366
|
+
startLocationUpdates();
|
|
367
|
+
}
|
|
368
|
+
} catch (Exception e) {
|
|
369
|
+
e.printStackTrace();
|
|
358
370
|
}
|
|
359
371
|
}
|
|
360
372
|
|
|
@@ -459,48 +471,15 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
459
471
|
}
|
|
460
472
|
|
|
461
473
|
private void getPeriodicalLocationUpdates() throws Exception {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
File baseDirectory = mInterfaceUtil.rootDirectory;
|
|
471
|
-
File exist_time_profile = new File(baseDirectory, mInterfaceUtil.packageName + "/time_profile.txt");
|
|
472
|
-
if (exist_time_profile.exists()) {
|
|
473
|
-
exist_time_profile.delete();
|
|
474
|
-
}
|
|
475
|
-
String serverTimeObj;
|
|
476
|
-
SimpleDateFormat simpleDateFormat;
|
|
477
|
-
StringBuilder timeObj;
|
|
478
|
-
String currentLine;
|
|
479
|
-
BufferedReader readerObj;
|
|
480
|
-
JSONObject serverDateObj;
|
|
481
|
-
timeObj = new StringBuilder();
|
|
482
|
-
BufferedWriter writerObj;
|
|
483
|
-
readerObj = new BufferedReader(new FileReader(new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "time_profile_encrypted.txt")));
|
|
484
|
-
while ((currentLine = readerObj.readLine()) != null) {
|
|
485
|
-
timeObj.append(currentLine);
|
|
474
|
+
try {
|
|
475
|
+
locationUpdateInd = "true";
|
|
476
|
+
mInterfaceUtil.timerInd = "running";
|
|
477
|
+
if (mGoogleApiClient.isConnected()) {
|
|
478
|
+
startLocationUpdates();
|
|
479
|
+
}
|
|
480
|
+
} catch (Exception e) {
|
|
481
|
+
e.printStackTrace();
|
|
486
482
|
}
|
|
487
|
-
readerObj.close();
|
|
488
|
-
serverDateObj = new JSONObject(decrypt(timeObj.toString()));
|
|
489
|
-
serverTimeObj = serverDateObj.optString("serverDate").toString();
|
|
490
|
-
|
|
491
|
-
// ******SERVER TIME ******//
|
|
492
|
-
SimpleDateFormat sdf = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", new mInterfaceUtil().locale);
|
|
493
|
-
//String currentDateandTime = sdf.format(new Date());
|
|
494
|
-
simpleDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss", new mInterfaceUtil().locale);
|
|
495
|
-
Date date = simpleDateFormat.parse(serverTimeObj);
|
|
496
|
-
long a = date.getTime() + 60000;
|
|
497
|
-
date.setTime(a);
|
|
498
|
-
serverTimeObj = simpleDateFormat.format(date);
|
|
499
|
-
serverDateObj.put("serverDate", serverTimeObj);
|
|
500
|
-
writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/" + "time_profile_encrypted.txt")));
|
|
501
|
-
writerObj.write(mInterfaceUtil.encrypt(serverDateObj.toString()));
|
|
502
|
-
writerObj.flush();
|
|
503
|
-
writerObj.close();
|
|
504
483
|
}
|
|
505
484
|
|
|
506
485
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
@@ -647,51 +626,71 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
647
626
|
public void onTaskRemoved(Intent rootIntent) {
|
|
648
627
|
super.onTaskRemoved(rootIntent);
|
|
649
628
|
|
|
650
|
-
|
|
651
|
-
setQueueInterval
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
setTimerIntervel
|
|
629
|
+
try {
|
|
630
|
+
if (setQueueInterval != null) {
|
|
631
|
+
setQueueInterval.cancel();
|
|
632
|
+
}
|
|
633
|
+
if (setTimerIntervel != null) {
|
|
634
|
+
setTimerIntervel.cancel();
|
|
635
|
+
}
|
|
636
|
+
Intent restartService = new Intent(getApplicationContext(),
|
|
637
|
+
this.getClass());
|
|
638
|
+
restartService.setPackage(getPackageName());
|
|
639
|
+
PendingIntent restartServicePI;
|
|
640
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
641
|
+
restartServicePI = PendingIntent.getService(
|
|
642
|
+
getApplicationContext(), 1, restartService,
|
|
643
|
+
PendingIntent.FLAG_IMMUTABLE);
|
|
644
|
+
}
|
|
645
|
+
else
|
|
646
|
+
{
|
|
647
|
+
restartServicePI = PendingIntent.getService(
|
|
648
|
+
getApplicationContext(), 1, restartService,
|
|
649
|
+
PendingIntent.FLAG_ONE_SHOT);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
|
|
653
|
+
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, restartServicePI);
|
|
654
|
+
} catch (Exception e) {
|
|
655
|
+
e.printStackTrace();
|
|
655
656
|
}
|
|
656
|
-
Intent restartService = new Intent(getApplicationContext(),
|
|
657
|
-
this.getClass());
|
|
658
|
-
restartService.setPackage(getPackageName());
|
|
659
|
-
PendingIntent restartServicePI = PendingIntent.getService(
|
|
660
|
-
getApplicationContext(), 1, restartService,
|
|
661
|
-
PendingIntent.FLAG_ONE_SHOT);
|
|
662
|
-
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
|
|
663
|
-
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 2000, restartServicePI);
|
|
664
657
|
}
|
|
665
658
|
|
|
666
659
|
/* WHEN THE RAM IS LOW */
|
|
667
660
|
@Override
|
|
668
661
|
public void onLowMemory() {
|
|
669
662
|
super.onLowMemory();
|
|
663
|
+
try {
|
|
664
|
+
if (setQueueInterval != null) {
|
|
665
|
+
setQueueInterval.cancel();
|
|
666
|
+
}
|
|
670
667
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
668
|
+
if (setTimerIntervel != null) {
|
|
669
|
+
setTimerIntervel.cancel();
|
|
670
|
+
}
|
|
674
671
|
|
|
675
|
-
|
|
676
|
-
|
|
672
|
+
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
673
|
+
} catch (Exception e) {
|
|
674
|
+
e.printStackTrace();
|
|
677
675
|
}
|
|
678
|
-
|
|
679
|
-
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
680
676
|
}
|
|
681
677
|
|
|
682
678
|
/* USER CLICK FORCE STOP IN SETTINGS */
|
|
683
679
|
@Override
|
|
684
680
|
public void onDestroy() {
|
|
685
681
|
super.onDestroy();
|
|
682
|
+
try {
|
|
683
|
+
if (setQueueInterval != null) {
|
|
684
|
+
setQueueInterval.cancel();
|
|
685
|
+
}
|
|
686
686
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
687
|
+
if (setTimerIntervel != null) {
|
|
688
|
+
setTimerIntervel.cancel();
|
|
689
|
+
}
|
|
690
|
+
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
691
|
+
} catch (Exception e) {
|
|
692
|
+
e.printStackTrace();
|
|
693
693
|
}
|
|
694
|
-
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
695
694
|
}
|
|
696
695
|
|
|
697
696
|
public boolean isConnected() {
|
package/src/ios/mInterface.h
CHANGED
package/src/ios/mInterface.m
CHANGED
|
@@ -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 = @"
|
|
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]
|
|
2018
|
-
|
|
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
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
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];
|