cordova-plugin-mserviceinterface-2.0 1.0.67 → 1.0.69
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/mInterface.java +84 -38
- package/src/android/mInterfaceService.java +38 -63
- package/src/android/mInterfaceUtil.java +114 -65
- package/src/ios/mInterface.h +1 -0
- package/src/ios/mInterface.m +468 -240
package/src/ios/mInterface.m
CHANGED
|
@@ -87,7 +87,6 @@
|
|
|
87
87
|
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
|
|
91
90
|
-(void)getAppStateInfoCall:(CDVInvokedUrlCommand *)command {
|
|
92
91
|
NSString *directory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
93
92
|
NSString *contentsPath = [NSString stringWithFormat:@"%@/%@/%@/%@/app_state_info.txt", directory, [self GetAppName], clientID, countryCode];
|
|
@@ -146,8 +145,39 @@
|
|
|
146
145
|
-(void)DownloadAppStateInfo:(CDVInvokedUrlCommand *)command{
|
|
147
146
|
@try {
|
|
148
147
|
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
149
|
-
|
|
148
|
+
//getting API Keys
|
|
150
149
|
NSError *jsonError;
|
|
150
|
+
NSString *getKeyApsx = [NSString stringWithFormat:@"%@/common/components/Keys/RetrieveKey.aspx", clientUrl];
|
|
151
|
+
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\",\"version\":\"doubleo\"}",clientID, countryCode];
|
|
152
|
+
NSMutableURLRequest *authRequest1 = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:getKeyApsx]];
|
|
153
|
+
[authRequest1 setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
154
|
+
[authRequest1 setHTTPMethod : @"POST"];
|
|
155
|
+
[authRequest1 setHTTPBody : [keyContent dataUsingEncoding:NSUTF8StringEncoding]];
|
|
156
|
+
NSURLResponse *keyResponse;
|
|
157
|
+
NSData *keyResponseData = [NSURLConnection sendSynchronousRequest:authRequest1 returningResponse:&keyResponse error:&jsonError];
|
|
158
|
+
NSString *responseString1 = [[NSString alloc] initWithData:keyResponseData encoding:NSUTF8StringEncoding];
|
|
159
|
+
NSData *keyData = [responseString1 dataUsingEncoding:NSUTF8StringEncoding];
|
|
160
|
+
|
|
161
|
+
NSString *filePath = [NSString stringWithFormat:@"%@/%@/my_accounts/%@_%@.json", directory, [self GetAppName], clientID, countryCode];
|
|
162
|
+
// Read the existing JSON data from the file
|
|
163
|
+
NSError* readError;
|
|
164
|
+
NSString* fileContents = [NSString stringWithContentsOfFile:filePath
|
|
165
|
+
encoding:NSUTF8StringEncoding
|
|
166
|
+
error:&readError];
|
|
167
|
+
// Parse the existing data as JSON
|
|
168
|
+
NSData* jsonData = [fileContents dataUsingEncoding:NSUTF8StringEncoding];
|
|
169
|
+
NSMutableDictionary* existingData = [NSJSONSerialization JSONObjectWithData:jsonData
|
|
170
|
+
options:NSJSONReadingMutableContainers
|
|
171
|
+
error:nil];
|
|
172
|
+
existingData[@"keys"] = [NSJSONSerialization JSONObjectWithData:keyData options:NSJSONReadingMutableContainers error:nil];
|
|
173
|
+
// Convert the updated data back to JSON
|
|
174
|
+
NSData* updatedJsonData = [NSJSONSerialization dataWithJSONObject:existingData
|
|
175
|
+
options:NSJSONWritingPrettyPrinted
|
|
176
|
+
error:nil];
|
|
177
|
+
// Write the updated JSON data back to the file
|
|
178
|
+
[updatedJsonData writeToFile:filePath atomically:YES];
|
|
179
|
+
|
|
180
|
+
NSString *contentsPath = [NSString stringWithFormat:@"%@/%@/%@/%@/app_state_info.txt", directory, [self GetAppName], clientID, countryCode];
|
|
151
181
|
NSString *authAspx = [NSString stringWithFormat:@"%@/get_app_state_info.aspx", cvsUrl];
|
|
152
182
|
NSString *deviceAspx = [NSString stringWithFormat:@"%@/api/security/validate_device", clientUrl];
|
|
153
183
|
NSDictionary *authDict = @{
|
|
@@ -264,72 +294,130 @@
|
|
|
264
294
|
return @"true";
|
|
265
295
|
}
|
|
266
296
|
|
|
267
|
-
-(void) UpdateAppStateInfo {
|
|
297
|
+
-(void) UpdateAppStateInfo: (NSData *)accountJsonData{
|
|
268
298
|
@try {
|
|
269
299
|
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
270
|
-
NSString *contentsPath = [NSString stringWithFormat:@"%@/%@/%@/%@/app_state_info.txt", directory, [self GetAppName], clientID, countryCode];
|
|
271
300
|
NSError *jsonError;
|
|
272
|
-
NSString *
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
@"country_code"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
@"
|
|
284
|
-
@"
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
301
|
+
NSString *contentsPath;
|
|
302
|
+
NSDictionary *accountDict = [NSJSONSerialization JSONObjectWithData:accountJsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
303
|
+
if (!jsonError && accountDict) {
|
|
304
|
+
NSString *clientID = accountDict[@"client_id"];
|
|
305
|
+
NSString *countryCode = accountDict[@"country_code"];
|
|
306
|
+
NSString *appID = [NSString stringWithFormat:@"%@", app_id];
|
|
307
|
+
NSString *platform = @"iOS";
|
|
308
|
+
NSString *store = @"AppleAppStore";
|
|
309
|
+
NSString *deviceID = accountDict[@"device_id"];
|
|
310
|
+
NSString *sessionID = accountDict[@"session_id"];
|
|
311
|
+
NSString *userID = accountDict[@"user_id"];
|
|
312
|
+
NSString *localeID = accountDict[@"locale_id"];
|
|
313
|
+
NSString *cvsUrl = accountDict[@"cvs_url"];
|
|
314
|
+
NSString *clientUrl = accountDict[@"client_url"];
|
|
315
|
+
|
|
316
|
+
//getting API Keys
|
|
317
|
+
NSError *jsonError;
|
|
318
|
+
NSString *getKeyApsx = [NSString stringWithFormat:@"%@/common/components/Keys/RetrieveKey.aspx", clientUrl];
|
|
319
|
+
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\",\"version\":\"doubleo\"}",clientID, countryCode];
|
|
320
|
+
NSMutableURLRequest *authRequest1 = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:getKeyApsx]];
|
|
321
|
+
[authRequest1 setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
322
|
+
[authRequest1 setHTTPMethod : @"POST"];
|
|
323
|
+
[authRequest1 setHTTPBody : [keyContent dataUsingEncoding:NSUTF8StringEncoding]];
|
|
324
|
+
NSURLResponse *keyResponse;
|
|
325
|
+
NSData *keyResponseData = [NSURLConnection sendSynchronousRequest:authRequest1 returningResponse:&keyResponse error:&jsonError];
|
|
326
|
+
NSString *responseString1 = [[NSString alloc] initWithData:keyResponseData encoding:NSUTF8StringEncoding];
|
|
327
|
+
NSData *keyData = [responseString1 dataUsingEncoding:NSUTF8StringEncoding];
|
|
328
|
+
|
|
329
|
+
NSString *filePath = [NSString stringWithFormat:@"%@/%@/my_accounts/%@_%@.json", directory, [self GetAppName], clientID, countryCode];
|
|
330
|
+
// Read the existing JSON data from the file
|
|
331
|
+
NSError* readError;
|
|
332
|
+
NSString* fileContents = [NSString stringWithContentsOfFile:filePath
|
|
333
|
+
encoding:NSUTF8StringEncoding
|
|
334
|
+
error:&readError];
|
|
335
|
+
// Parse the existing data as JSON
|
|
336
|
+
NSData* jsonData = [fileContents dataUsingEncoding:NSUTF8StringEncoding];
|
|
337
|
+
NSMutableDictionary* existingData = [NSJSONSerialization JSONObjectWithData:jsonData
|
|
338
|
+
options:NSJSONReadingMutableContainers
|
|
339
|
+
error:nil];
|
|
340
|
+
existingData[@"keys"] = [NSJSONSerialization JSONObjectWithData:keyData options:NSJSONReadingMutableContainers error:nil];
|
|
341
|
+
// Convert the updated data back to JSON
|
|
342
|
+
NSData* updatedJsonData = [NSJSONSerialization dataWithJSONObject:existingData
|
|
343
|
+
options:NSJSONWritingPrettyPrinted
|
|
344
|
+
error:nil];
|
|
345
|
+
// Write the updated JSON data back to the file
|
|
346
|
+
[updatedJsonData writeToFile:filePath atomically:YES];
|
|
347
|
+
|
|
348
|
+
contentsPath = [NSString stringWithFormat:@"%@/%@/%@/%@/app_state_info.txt", directory, [self GetAppName], clientID, countryCode];
|
|
349
|
+
NSString *authAspx = [NSString stringWithFormat:@"%@/get_app_state_info.aspx", cvsUrl];
|
|
350
|
+
NSString *deviceAspx = [NSString stringWithFormat:@"%@/api/security/validate_device", clientUrl];
|
|
351
|
+
NSDictionary *authDict = @{
|
|
352
|
+
@"client_id" : clientID,
|
|
353
|
+
@"country_code" : countryCode,
|
|
354
|
+
@"app_id" : appID,
|
|
355
|
+
@"platform" : platform,
|
|
356
|
+
@"store" : store
|
|
357
|
+
};
|
|
358
|
+
NSDictionary *inputParamDict = @{
|
|
359
|
+
@"p_device_id" : deviceID,
|
|
360
|
+
@"p_company_id" : clientID,
|
|
361
|
+
@"p_country_code" : countryCode,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
NSDictionary *contextDict = @{
|
|
365
|
+
@"sessionId" : sessionID,
|
|
366
|
+
@"userId" : userID,
|
|
367
|
+
@"client_id" : clientID,
|
|
368
|
+
@"locale_id" : localeID,
|
|
369
|
+
@"country_code" : countryCode,
|
|
370
|
+
@"inputparam" : inputParamDict
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
NSDictionary *inputDict = @{
|
|
374
|
+
@"context" : contextDict,
|
|
375
|
+
};
|
|
376
|
+
NSData * authJSONData = [NSJSONSerialization dataWithJSONObject:authDict options:0 error:&jsonError];
|
|
377
|
+
NSString * authDataString = [[NSString alloc] initWithData:authJSONData encoding:NSUTF8StringEncoding];
|
|
378
|
+
NSMutableURLRequest *authRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:authAspx]];
|
|
379
|
+
[authRequest setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
380
|
+
[authRequest setHTTPMethod : @"POST"];
|
|
381
|
+
[authRequest setHTTPBody : [authDataString dataUsingEncoding:NSUTF8StringEncoding]];
|
|
382
|
+
NSURLResponse *authResponse;
|
|
383
|
+
NSData *authResponseData = [NSURLConnection sendSynchronousRequest:authRequest returningResponse:&authResponse error:&jsonError];
|
|
384
|
+
NSString *responseString = [[NSString alloc] initWithData:authResponseData encoding:NSUTF8StringEncoding];
|
|
385
|
+
NSMutableDictionary * mutableDict = [[NSMutableDictionary alloc] init];
|
|
386
|
+
mutableDict = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&jsonError];
|
|
387
|
+
//For device authentication
|
|
388
|
+
@try {
|
|
389
|
+
NSData * deviceJSONData = [NSJSONSerialization dataWithJSONObject:inputDict options:0 error:&jsonError];
|
|
390
|
+
NSString * deviceDataString = [[NSString alloc] initWithData:deviceJSONData encoding:NSUTF8StringEncoding];
|
|
391
|
+
NSData *deviceData = [deviceDataString dataUsingEncoding:NSUTF8StringEncoding];
|
|
392
|
+
NSMutableURLRequest *deviceRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:deviceAspx]];
|
|
393
|
+
[deviceRequest setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
394
|
+
[deviceRequest setHTTPMethod : @"POST"];
|
|
395
|
+
[deviceRequest setHTTPBody : deviceData];
|
|
396
|
+
NSURLResponse *deviceResponse;
|
|
397
|
+
NSData *deviceResponseData = [NSURLConnection sendSynchronousRequest:deviceRequest returningResponse:&deviceResponse error:nil];
|
|
398
|
+
NSString *deviceResponseString = [[NSString alloc] initWithData:deviceResponseData encoding:NSUTF8StringEncoding];
|
|
399
|
+
if (deviceResponseData != nil) {
|
|
400
|
+
NSMutableDictionary *deviceResponseDict = [[NSMutableDictionary alloc] init];
|
|
401
|
+
deviceResponseDict = [NSJSONSerialization JSONObjectWithData:[deviceResponseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&jsonError];
|
|
402
|
+
NSMutableDictionary *deviceIndDict = [[NSMutableDictionary alloc] init];
|
|
403
|
+
deviceIndDict = deviceResponseDict[@"outputparam"];
|
|
404
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
405
|
+
dict[@"accessPackageTimestamp"] = mutableDict[@"accessPackageTimestamp"];
|
|
406
|
+
dict[@"appVersion"] = mutableDict[@"appVersion"];
|
|
407
|
+
dict[@"configurationPackageTimestamp"] = mutableDict[@"configurationPackageTimestamp"];
|
|
408
|
+
dict[@"validDevice"] = @"true";
|
|
409
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
|
|
410
|
+
[jsonData writeToFile:contentsPath atomically:true];
|
|
411
|
+
} else {
|
|
412
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
413
|
+
dict[@"accessPackageTimestamp"] = mutableDict[@"accessPackageTimestamp"];
|
|
414
|
+
dict[@"appVersion"] = mutableDict[@"appVersion"];
|
|
415
|
+
dict[@"configurationPackageTimestamp"] = mutableDict[@"configurationPackageTimestamp"];
|
|
416
|
+
dict[@"validDevice"] = @"nostatus";
|
|
417
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
|
|
418
|
+
[jsonData writeToFile:contentsPath atomically:true];
|
|
419
|
+
}
|
|
420
|
+
} @catch (NSException *exception) {
|
|
333
421
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
334
422
|
dict[@"accessPackageTimestamp"] = mutableDict[@"accessPackageTimestamp"];
|
|
335
423
|
dict[@"appVersion"] = mutableDict[@"appVersion"];
|
|
@@ -338,52 +426,71 @@
|
|
|
338
426
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
|
|
339
427
|
[jsonData writeToFile:contentsPath atomically:true];
|
|
340
428
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
dict[@"appVersion"] = mutableDict[@"appVersion"];
|
|
345
|
-
dict[@"configurationPackageTimestamp"] = mutableDict[@"configurationPackageTimestamp"];
|
|
346
|
-
dict[@"validDevice"] = @"nostatus";
|
|
347
|
-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
|
|
348
|
-
[jsonData writeToFile:contentsPath atomically:true];
|
|
429
|
+
|
|
430
|
+
}else {
|
|
431
|
+
NSLog(@"Error parsing accountJsonData: %@", jsonError);
|
|
349
432
|
}
|
|
350
433
|
} @catch (NSException *exception) {
|
|
351
434
|
NSLog(@"Exception : %@", exception.description);
|
|
352
435
|
}
|
|
353
436
|
}
|
|
354
437
|
|
|
438
|
+
|
|
355
439
|
- (void)ValidateAppStateInfo {
|
|
356
440
|
NSString *directory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
357
|
-
NSString *
|
|
441
|
+
NSString *myAccountsFolderPath = [NSString stringWithFormat:@"%@/%@/%@", directory, [self GetAppName], @"my_accounts"];
|
|
442
|
+
NSError *error;
|
|
443
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
358
444
|
InternetConnection *networkReachability = [InternetConnection reachabilityForInternetConnection];
|
|
359
445
|
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
|
|
360
|
-
if([
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
446
|
+
if ([fileManager fileExistsAtPath:myAccountsFolderPath]) {
|
|
447
|
+
NSArray *accountFiles = [fileManager contentsOfDirectoryAtPath:myAccountsFolderPath error:&error];
|
|
448
|
+
if (accountFiles) {
|
|
449
|
+
for (NSString *accountFileName in accountFiles) {
|
|
450
|
+
if ([accountFileName.pathExtension isEqualToString:@"json"]) {
|
|
451
|
+
NSString *accountFilePath = [myAccountsFolderPath stringByAppendingPathComponent:accountFileName];
|
|
452
|
+
NSData *accountJsonData = [NSData dataWithContentsOfFile:accountFilePath];
|
|
453
|
+
if (accountJsonData) {
|
|
454
|
+
NSMutableDictionary *accountDict = [NSJSONSerialization JSONObjectWithData:accountJsonData options:NSJSONReadingMutableContainers error:nil];
|
|
455
|
+
NSString *accountClientID = accountDict[@"client_id"];
|
|
456
|
+
NSString *accountCountryCode = accountDict[@"country_code"];
|
|
457
|
+
NSString *contentsPath = [NSString stringWithFormat:@"%@/%@/%@/%@/app_state_info.txt", directory, [self GetAppName], accountClientID, accountCountryCode];
|
|
458
|
+
if ([[NSFileManager defaultManager] fileExistsAtPath:contentsPath]) {
|
|
459
|
+
NSData *fileData = [NSData dataWithContentsOfFile:contentsPath];
|
|
460
|
+
NSMutableDictionary *fileDict = [NSJSONSerialization JSONObjectWithData:fileData options:NSJSONReadingMutableContainers error:nil];
|
|
461
|
+
NSString *deviceStatus = fileDict[@"validDevice"];
|
|
462
|
+
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:contentsPath error:nil];
|
|
463
|
+
NSDateFormatter *dateFormatter = [self getCurrentDateTime];
|
|
464
|
+
[dateFormatter setDateFormat:@"yyyyMMdd"];
|
|
465
|
+
NSString *lastModified = [dateFormatter stringFromDate:[attributes fileModificationDate]];
|
|
466
|
+
NSString *currentDate = [dateFormatter stringFromDate:[NSDate date]];
|
|
467
|
+
int lastModifiedInt = [lastModified intValue];
|
|
468
|
+
int currentDateInt = [currentDate intValue];
|
|
469
|
+
|
|
470
|
+
if([deviceStatus isEqualToString:@"nostatus"] || lastModifiedInt != currentDateInt) {
|
|
471
|
+
if(networkStatus != NotReachable){
|
|
472
|
+
[self UpdateAppStateInfo :accountJsonData];
|
|
473
|
+
} else {
|
|
474
|
+
[self HandleAppStateTimer:@"success"];
|
|
475
|
+
}
|
|
476
|
+
}else {
|
|
477
|
+
[self HandleAppStateTimer:@"success"];
|
|
478
|
+
}
|
|
479
|
+
}else {
|
|
480
|
+
if(networkStatus != NotReachable){
|
|
481
|
+
[self UpdateAppStateInfo :accountJsonData];
|
|
482
|
+
} else {
|
|
483
|
+
[self HandleAppStateTimer:@"success"];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
377
488
|
}
|
|
378
489
|
} else {
|
|
379
|
-
|
|
490
|
+
NSLog(@"Error in reading my_accounts folder contents: %@", error);
|
|
380
491
|
}
|
|
381
492
|
} else {
|
|
382
|
-
|
|
383
|
-
[self UpdateAppStateInfo];
|
|
384
|
-
} else {
|
|
385
|
-
[self HandleAppStateTimer:@"success"];
|
|
386
|
-
}
|
|
493
|
+
NSLog(@"my_accounts folder not found..");
|
|
387
494
|
}
|
|
388
495
|
}
|
|
389
496
|
|
|
@@ -937,7 +1044,7 @@
|
|
|
937
1044
|
@try {
|
|
938
1045
|
NSError *jsonError;
|
|
939
1046
|
NSString *getKeyApsx = [NSString stringWithFormat:@"%@/common/components/Keys/RetrieveKey.aspx", clientUrl];
|
|
940
|
-
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\"}",clientId, countryCode];
|
|
1047
|
+
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\",,\"version\":\"doubleo\"}",clientId, countryCode];
|
|
941
1048
|
NSMutableURLRequest *authRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:getKeyApsx]];
|
|
942
1049
|
[authRequest setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
943
1050
|
[authRequest setHTTPMethod : @"POST"];
|
|
@@ -1024,7 +1131,7 @@
|
|
|
1024
1131
|
@try {
|
|
1025
1132
|
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
1026
1133
|
NSString *locationFilePath = [NSString stringWithFormat:@"%@/%@/MyLocation_encrypted.txt", directory, [self GetAppName]];
|
|
1027
|
-
NSString *lastKnownPath = [NSString stringWithFormat:@"%@/%@/
|
|
1134
|
+
NSString *lastKnownPath = [NSString stringWithFormat:@"%@/%@/last_known_location.txt", directory, [self GetAppName]];
|
|
1028
1135
|
NSData *fileContents = [[NSData alloc] init];
|
|
1029
1136
|
NSFileManager *filemanager = [NSFileManager defaultManager];
|
|
1030
1137
|
if([filemanager fileExistsAtPath:locationFilePath] != YES){
|
|
@@ -1048,33 +1155,61 @@
|
|
|
1048
1155
|
if(networkStatus == NotReachable){
|
|
1049
1156
|
} else {
|
|
1050
1157
|
NSError *error;
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
NSString *
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1158
|
+
NSString *myAccountsFolderPath = [NSString stringWithFormat:@"%@/%@/%@", directory, [self GetAppName], @"my_accounts"];
|
|
1159
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
1160
|
+
if([fileManager fileExistsAtPath:myAccountsFolderPath]) {
|
|
1161
|
+
NSArray *files = [fileManager contentsOfDirectoryAtPath:myAccountsFolderPath error:&error];
|
|
1162
|
+
if (files) {
|
|
1163
|
+
NSMutableArray *myAccountsArray = [NSMutableArray array];
|
|
1164
|
+
for (NSString *fileName in files) {
|
|
1165
|
+
if ([fileName.pathExtension isEqualToString:@"json"]) {
|
|
1166
|
+
NSString *filePath = [myAccountsFolderPath stringByAppendingPathComponent:fileName];
|
|
1167
|
+
NSData *jsonData = [NSData dataWithContentsOfFile:filePath];
|
|
1168
|
+
if (jsonData) {
|
|
1169
|
+
NSError *jsonError;
|
|
1170
|
+
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
1171
|
+
if (!jsonError && jsonDict) {
|
|
1172
|
+
[myAccountsArray addObject:jsonDict];
|
|
1173
|
+
} else {
|
|
1174
|
+
NSLog(@"Error parsing JSON file %@: %@", fileName, jsonError);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
for( int index = 0; index < [myAccountsArray count]; index++ ) {
|
|
1180
|
+
NSString *locationUpdateInd = [myAccountsArray[index] valueForKey:@"location_update_ind"];
|
|
1181
|
+
if([locationUpdateInd isEqual: @"true"]) {
|
|
1182
|
+
NSString *clientId = [myAccountsArray[index] valueForKey:@"client_id"];
|
|
1183
|
+
NSString *countryCode = [myAccountsArray[index] valueForKey:@"country_code"];
|
|
1184
|
+
NSString *clientUrl = [myAccountsArray[index] valueForKey:@"client_url"];
|
|
1185
|
+
NSString *locationData = [NSString stringWithContentsOfFile:locationFilePath encoding:NSUTF8StringEncoding error:&error];
|
|
1186
|
+
NSString *baseURL = [NSString stringWithFormat:@"%@/common/components/GeoLocation/update_device_location_offline.aspx", clientUrl];
|
|
1187
|
+
NSString *content = [NSString stringWithFormat:@"<location_xml><client_id>%@</client_id><country_code>%@</country_code><device_id>%@</device_id><location>%@</location></location_xml>", clientId, countryCode, deviceID, locationData];
|
|
1188
|
+
NSData *inputData = [content dataUsingEncoding:NSUTF8StringEncoding];
|
|
1189
|
+
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:baseURL]];
|
|
1190
|
+
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
|
|
1191
|
+
[request setHTTPMethod : @"POST"];
|
|
1192
|
+
[request setHTTPBody : inputData];
|
|
1193
|
+
NSError *jsonError;
|
|
1194
|
+
NSURLResponse *response = nil;
|
|
1195
|
+
//[NSURLConnection connectionWithRequest:fileRequest delegate:self];
|
|
1196
|
+
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&jsonError];
|
|
1197
|
+
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
|
|
1198
|
+
|
|
1199
|
+
} else {
|
|
1200
|
+
NSLog(@"The locationUpdateInd indication is set to false");
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
// Emptying the text file
|
|
1204
|
+
[[NSData data] writeToFile:locationFilePath atomically:true];
|
|
1205
|
+
|
|
1071
1206
|
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1207
|
+
}else{
|
|
1208
|
+
NSLog(@"Error in reading files: %@", error);
|
|
1074
1209
|
}
|
|
1210
|
+
}else {
|
|
1211
|
+
NSLog(@"File not available at the path..");
|
|
1075
1212
|
}
|
|
1076
|
-
// Emptying the text file
|
|
1077
|
-
[[NSData data] writeToFile:locationFilePath atomically:true];
|
|
1078
1213
|
}
|
|
1079
1214
|
} @catch (NSException *exception) {
|
|
1080
1215
|
NSLog(@"SendLocation Exception is : %@", exception.description);
|
|
@@ -1082,13 +1217,14 @@
|
|
|
1082
1217
|
}];
|
|
1083
1218
|
}
|
|
1084
1219
|
|
|
1220
|
+
|
|
1085
1221
|
- (void)GetLocation:(CDVInvokedUrlCommand*)command
|
|
1086
1222
|
{
|
|
1087
1223
|
[self.commandDelegate runInBackground:^{
|
|
1088
1224
|
CDVPluginResult *result = nil;
|
|
1089
1225
|
@try {
|
|
1090
1226
|
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
1091
|
-
NSString * filePath = [NSString stringWithFormat:@"%@/%@%@",directory,[self GetAppName],@"/
|
|
1227
|
+
NSString * filePath = [NSString stringWithFormat:@"%@/%@%@",directory,[self GetAppName],@"/last_known_location.txt"];
|
|
1092
1228
|
NSError * error;
|
|
1093
1229
|
NSString * locationData = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
|
|
1094
1230
|
NSArray * mySplit = [locationData componentsSeparatedByString:@","];
|
|
@@ -1575,10 +1711,10 @@
|
|
|
1575
1711
|
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
|
|
1576
1712
|
|
|
1577
1713
|
}
|
|
1578
|
-
|
|
1579
1714
|
- (void)StartService:(CDVInvokedUrlCommand*)command
|
|
1580
1715
|
{
|
|
1581
1716
|
@try {
|
|
1717
|
+
[self ValidateAppStateInfo];
|
|
1582
1718
|
self.QueueToServerTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
|
|
1583
1719
|
target:self
|
|
1584
1720
|
selector:@selector(DespatchQueueMoveToServer)
|
|
@@ -1587,36 +1723,47 @@
|
|
|
1587
1723
|
double locationInterval = 0.0;
|
|
1588
1724
|
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
1589
1725
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
1590
|
-
NSString *locConfgFilePath = [NSString stringWithFormat:@"%@/%@/
|
|
1726
|
+
NSString *locConfgFilePath = [NSString stringWithFormat:@"%@/%@/app_controller.json.txt", directory, [self GetAppName]];
|
|
1591
1727
|
if([fileManager fileExistsAtPath:locConfgFilePath]){
|
|
1592
1728
|
NSData *user_data = [NSData dataWithContentsOfFile:locConfgFilePath];
|
|
1593
1729
|
NSError *jsonError = nil;
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1730
|
+
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:user_data options:0 error:&jsonError];
|
|
1731
|
+
if (!jsonError) {
|
|
1732
|
+
NSDictionary *locationConfig = jsonDict[@"location_configuration"];
|
|
1733
|
+
if (locationConfig) {
|
|
1734
|
+
NSString *locationFetchInterval = locationConfig[@"location_fetch_interval_in_seconds"];
|
|
1735
|
+
locationInterval = [locationFetchInterval doubleValue];
|
|
1736
|
+
if(locationInterval ==0) {
|
|
1737
|
+
NSLog(@"No location update should not be happnened..");
|
|
1738
|
+
} else {
|
|
1739
|
+
self.locationManager = [[CLLocationManager alloc] init];
|
|
1740
|
+
[self.locationManager setDelegate:self];
|
|
1741
|
+
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
|
|
1742
|
+
[self.locationManager setHeadingFilter:kCLHeadingFilterNone];
|
|
1743
|
+
[self.locationManager requestAlwaysAuthorization];
|
|
1744
|
+
[self.locationManager requestWhenInUseAuthorization];
|
|
1745
|
+
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
|
|
1746
|
+
if (status == kCLAuthorizationStatusAuthorizedAlways) {
|
|
1747
|
+
// Location permission is granted, enable background location updates
|
|
1748
|
+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
|
|
1749
|
+
_locationManager.allowsBackgroundLocationUpdates = YES;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
[self.locationManager startUpdatingLocation];
|
|
1753
|
+
[self KillTimers];
|
|
1754
|
+
self.LocationTimer = [NSTimer scheduledTimerWithTimeInterval:locationInterval
|
|
1755
|
+
target:self
|
|
1756
|
+
selector:@selector(SendLocation)
|
|
1757
|
+
userInfo:nil
|
|
1758
|
+
repeats:YES];
|
|
1759
|
+
}
|
|
1760
|
+
} else {
|
|
1761
|
+
NSLog(@"'location_configuration' key not found in JSON.");
|
|
1762
|
+
// Handle the absence of the key as needed.
|
|
1763
|
+
}
|
|
1599
1764
|
} else {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
|
|
1603
|
-
[self.locationManager setHeadingFilter:kCLHeadingFilterNone];
|
|
1604
|
-
[self.locationManager requestAlwaysAuthorization];
|
|
1605
|
-
[self.locationManager requestWhenInUseAuthorization];
|
|
1606
|
-
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
|
|
1607
|
-
if (status == kCLAuthorizationStatusAuthorizedAlways) {
|
|
1608
|
-
// Location permission is granted, enable background location updates
|
|
1609
|
-
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
|
|
1610
|
-
_locationManager.allowsBackgroundLocationUpdates = YES;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
[self.locationManager startUpdatingLocation];
|
|
1614
|
-
[self KillTimers];
|
|
1615
|
-
self.LocationTimer = [NSTimer scheduledTimerWithTimeInterval:locationInterval
|
|
1616
|
-
target:self
|
|
1617
|
-
selector:@selector(SendLocation)
|
|
1618
|
-
userInfo:nil
|
|
1619
|
-
repeats:YES];
|
|
1765
|
+
NSLog(@"Error parsing JSON: %@", jsonError);
|
|
1766
|
+
// Handle JSON parsing error as needed.
|
|
1620
1767
|
}
|
|
1621
1768
|
} else {
|
|
1622
1769
|
NSLog(@"There is no location config file..");
|
|
@@ -1657,119 +1804,167 @@
|
|
|
1657
1804
|
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
1658
1805
|
NSError *error;
|
|
1659
1806
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
1660
|
-
NSString *
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
NSString *databasePath = [NSString stringWithFormat:@"%@/%@/%@/%@/database", directory, [self GetAppName], clientId, countryCode];
|
|
1679
|
-
if([fileManager fileExistsAtPath:databasePath]) {
|
|
1680
|
-
for( int attachIndex = 0; attachIndex < [attachedFilesMutArr count]; attachIndex++ ) {
|
|
1681
|
-
NSString * attachedFilesPath = [NSString stringWithFormat:@"%@/%@", attachFolderPath, attachedFilesMutArr[attachIndex]];
|
|
1682
|
-
NSString *attachURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, attachedFilesMutArr[attachIndex]];
|
|
1683
|
-
statusIndication = [self sendFilesToServer:attachedFilesPath fileName:attachedFilesMutArr[attachIndex] requestURL:attachURL];
|
|
1684
|
-
if ([statusIndication isEqualToString:@"true"]) {
|
|
1685
|
-
breakIndication = @"true";
|
|
1686
|
-
break;
|
|
1807
|
+
NSString *myAccountsFolderPath = [NSString stringWithFormat:@"%@/%@/%@", directory, [self GetAppName], @"my_accounts"];
|
|
1808
|
+
|
|
1809
|
+
if([fileManager fileExistsAtPath:myAccountsFolderPath]) {
|
|
1810
|
+
NSArray *files = [fileManager contentsOfDirectoryAtPath:myAccountsFolderPath error:&error];
|
|
1811
|
+
if (files) {
|
|
1812
|
+
|
|
1813
|
+
NSMutableArray *myAccountsArray = [NSMutableArray array];
|
|
1814
|
+
for (NSString *fileName in files) {
|
|
1815
|
+
if ([fileName.pathExtension isEqualToString:@"json"]) {
|
|
1816
|
+
NSString *filePath = [myAccountsFolderPath stringByAppendingPathComponent:fileName];
|
|
1817
|
+
NSData *jsonData = [NSData dataWithContentsOfFile:filePath];
|
|
1818
|
+
if (jsonData) {
|
|
1819
|
+
NSError *jsonError;
|
|
1820
|
+
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
1821
|
+
if (!jsonError && jsonDict) {
|
|
1822
|
+
[myAccountsArray addObject:jsonDict];
|
|
1823
|
+
} else {
|
|
1824
|
+
NSLog(@"Error parsing JSON file %@: %@", fileName, jsonError);
|
|
1687
1825
|
}
|
|
1688
1826
|
}
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
InternetConnection *networkReachability = [InternetConnection reachabilityForInternetConnection];
|
|
1830
|
+
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
|
|
1831
|
+
if(networkStatus != NotReachable) {
|
|
1832
|
+
for( int index = 0; index < [myAccountsArray count]; index++ ) {
|
|
1833
|
+
NSString *clientId = [myAccountsArray[index] valueForKey:@"client_id"];
|
|
1834
|
+
NSString *countryCode = [myAccountsArray[index] valueForKey:@"country_code"];
|
|
1835
|
+
NSString *clientUrl = [myAccountsArray[index] valueForKey:@"client_url"];
|
|
1836
|
+
NSString *userID = [myAccountsArray[index] valueForKey:@"user_id"];
|
|
1837
|
+
NSString *attachFolderPath = [NSString stringWithFormat:@"%@/%@/%@/%@/database/attachments", directory, [self GetAppName], clientId, countryCode];
|
|
1838
|
+
NSString *queueFolderPath = [NSString stringWithFormat:@"%@/%@/%@/%@/database/queue", directory, [self GetAppName], clientId, countryCode];
|
|
1839
|
+
NSArray *attachedFilesArr = [fileManager contentsOfDirectoryAtPath:attachFolderPath error:&error];
|
|
1840
|
+
NSMutableArray *attachedFilesMutArr = [attachedFilesArr mutableCopy];
|
|
1841
|
+
if([attachedFilesMutArr containsObject:@".DS_Store"]) {
|
|
1842
|
+
[attachedFilesMutArr removeObject:@".DS_Store"];
|
|
1843
|
+
}
|
|
1844
|
+
NSString *databasePath = [NSString stringWithFormat:@"%@/%@/%@/%@/database", directory, [self GetAppName], clientId, countryCode];
|
|
1845
|
+
if([fileManager fileExistsAtPath:databasePath]) {
|
|
1846
|
+
for( int attachIndex = 0; attachIndex < [attachedFilesMutArr count]; attachIndex++ ) {
|
|
1847
|
+
NSString * attachedFilesPath = [NSString stringWithFormat:@"%@/%@", attachFolderPath, attachedFilesMutArr[attachIndex]];
|
|
1848
|
+
NSString *attachURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, attachedFilesMutArr[attachIndex]];
|
|
1849
|
+
statusIndication = [self sendFilesToServer:attachedFilesPath fileName:attachedFilesMutArr[attachIndex] requestURL:attachURL];
|
|
1850
|
+
if ([statusIndication isEqualToString:@"true"]) {
|
|
1851
|
+
breakIndication = @"true";
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1694
1854
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
[
|
|
1855
|
+
if ([statusIndication isEqualToString:@"false"]) {
|
|
1856
|
+
NSArray *queueFilesArr = [fileManager contentsOfDirectoryAtPath:queueFolderPath error:&error];
|
|
1857
|
+
NSMutableArray *queueFilesMutArr = [queueFilesArr mutableCopy];
|
|
1858
|
+
if([queueFilesMutArr containsObject:@".DS_Store"]) {
|
|
1859
|
+
[queueFilesMutArr removeObject:@".DS_Store"];
|
|
1860
|
+
}
|
|
1861
|
+
for( int queueIndex = 0; queueIndex < [queueFilesMutArr count]; queueIndex++ ) {
|
|
1862
|
+
NSString *queueFilesPath = [NSString stringWithFormat:@"%@/%@", queueFolderPath, queueFilesMutArr[queueIndex]];
|
|
1863
|
+
NSString *queueURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, queueFilesMutArr[queueIndex]];
|
|
1864
|
+
[self sendFilesToServer:queueFilesPath fileName:queueFilesMutArr[queueIndex] requestURL:queueURL];
|
|
1865
|
+
}
|
|
1699
1866
|
}
|
|
1867
|
+
} else {
|
|
1868
|
+
NSLog(@"No database directory found at the path..");
|
|
1869
|
+
}
|
|
1870
|
+
if ([breakIndication isEqualToString:@"false"]) {
|
|
1871
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
1872
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1873
|
+
} else {
|
|
1874
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
|
1875
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1700
1876
|
}
|
|
1701
|
-
} else {
|
|
1702
|
-
NSLog(@"No database directory found at the path..");
|
|
1703
|
-
}
|
|
1704
|
-
if ([breakIndication isEqualToString:@"false"]) {
|
|
1705
|
-
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
1706
|
-
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1707
|
-
} else {
|
|
1708
|
-
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
|
1709
|
-
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1710
1877
|
}
|
|
1878
|
+
} else {
|
|
1879
|
+
NSLog(@"No Internet connection..");
|
|
1711
1880
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
}
|
|
1881
|
+
}else{
|
|
1882
|
+
NSLog(@"Error in reading files: %@", error);
|
|
1883
|
+
}
|
|
1884
|
+
}else {
|
|
1716
1885
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
|
1717
1886
|
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1718
1887
|
}
|
|
1719
1888
|
}];
|
|
1720
1889
|
}
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
1890
|
-(void)DespatchQueueMoveToServer {
|
|
1724
1891
|
[self.commandDelegate runInBackground:^{
|
|
1725
1892
|
NSString *statusIndication = @"false";
|
|
1726
1893
|
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
1727
1894
|
NSError *error;
|
|
1728
1895
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
NSString *attachURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, attachedFilesMutArr[attachIndex]];
|
|
1750
|
-
statusIndication = [self sendFilesToServer:attachedFilesPath fileName:attachedFilesMutArr[attachIndex] requestURL:attachURL];
|
|
1751
|
-
if ([statusIndication isEqualToString:@"true"]) {
|
|
1752
|
-
break;
|
|
1896
|
+
|
|
1897
|
+
NSString *myAccountsFolderPath = [NSString stringWithFormat:@"%@/%@/%@", directory, [self GetAppName], @"my_accounts"];
|
|
1898
|
+
|
|
1899
|
+
if([fileManager fileExistsAtPath:myAccountsFolderPath]) {
|
|
1900
|
+
NSArray *files = [fileManager contentsOfDirectoryAtPath:myAccountsFolderPath error:&error];
|
|
1901
|
+
if (files) {
|
|
1902
|
+
|
|
1903
|
+
NSMutableArray *myAccountsArray = [NSMutableArray array];
|
|
1904
|
+
for (NSString *fileName in files) {
|
|
1905
|
+
if ([fileName.pathExtension isEqualToString:@"json"]) {
|
|
1906
|
+
NSString *filePath = [myAccountsFolderPath stringByAppendingPathComponent:fileName];
|
|
1907
|
+
NSData *jsonData = [NSData dataWithContentsOfFile:filePath];
|
|
1908
|
+
if (jsonData) {
|
|
1909
|
+
NSError *jsonError;
|
|
1910
|
+
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
1911
|
+
if (!jsonError && jsonDict) {
|
|
1912
|
+
[myAccountsArray addObject:jsonDict];
|
|
1913
|
+
} else {
|
|
1914
|
+
NSLog(@"Error parsing JSON file %@: %@", fileName, jsonError);
|
|
1915
|
+
}
|
|
1753
1916
|
}
|
|
1754
1917
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1918
|
+
}
|
|
1919
|
+
InternetConnection *networkReachability = [InternetConnection reachabilityForInternetConnection];
|
|
1920
|
+
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
|
|
1921
|
+
if(networkStatus != NotReachable) {
|
|
1922
|
+
for( int index = 0; index < [myAccountsArray count]; index++ ) {
|
|
1923
|
+
NSString *clientId = [myAccountsArray[index] valueForKey:@"client_id"];
|
|
1924
|
+
NSString *countryCode = [myAccountsArray[index] valueForKey:@"country_code"];
|
|
1925
|
+
NSString *clientUrl = [myAccountsArray[index] valueForKey:@"client_url"];
|
|
1926
|
+
NSString *userID = [myAccountsArray[index] valueForKey:@"user_id"];
|
|
1927
|
+
NSString *attachFolderPath = [NSString stringWithFormat:@"%@/%@/%@/%@/database/attachments", directory, [self GetAppName], clientId, countryCode];
|
|
1928
|
+
NSString *queueFolderPath = [NSString stringWithFormat:@"%@/%@/%@/%@/database/queue", directory, [self GetAppName], clientId, countryCode];
|
|
1929
|
+
NSArray *attachedFilesArr = [fileManager contentsOfDirectoryAtPath:attachFolderPath error:&error];
|
|
1930
|
+
NSMutableArray *attachedFilesMutArr = [attachedFilesArr mutableCopy];
|
|
1931
|
+
if([attachedFilesMutArr containsObject:@".DS_Store"]) {
|
|
1932
|
+
[attachedFilesMutArr removeObject:@".DS_Store"];
|
|
1760
1933
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1934
|
+
NSString *databasePath = [NSString stringWithFormat:@"%@/%@/%@/%@/database", directory, [self GetAppName], clientId, countryCode];
|
|
1935
|
+
if([fileManager fileExistsAtPath:databasePath]) {
|
|
1936
|
+
for( int attachIndex = 0; attachIndex < [attachedFilesMutArr count]; attachIndex++ ) {
|
|
1937
|
+
NSString * attachedFilesPath = [NSString stringWithFormat:@"%@/%@", attachFolderPath, attachedFilesMutArr[attachIndex]];
|
|
1938
|
+
NSString *attachURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, attachedFilesMutArr[attachIndex]];
|
|
1939
|
+
statusIndication = [self sendFilesToServer:attachedFilesPath fileName:attachedFilesMutArr[attachIndex] requestURL:attachURL];
|
|
1940
|
+
if ([statusIndication isEqualToString:@"true"]) {
|
|
1941
|
+
break;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if ([statusIndication isEqualToString:@"false"]) {
|
|
1945
|
+
NSArray *queueFilesArr = [fileManager contentsOfDirectoryAtPath:queueFolderPath error:&error];
|
|
1946
|
+
NSMutableArray *queueFilesMutArr = [queueFilesArr mutableCopy];
|
|
1947
|
+
if([queueFilesMutArr containsObject:@".DS_Store"]) {
|
|
1948
|
+
[queueFilesMutArr removeObject:@".DS_Store"];
|
|
1949
|
+
}
|
|
1950
|
+
for( int queueIndex = 0; queueIndex < [queueFilesMutArr count]; queueIndex++ ) {
|
|
1951
|
+
NSString *queueFilesPath = [NSString stringWithFormat:@"%@/%@", queueFolderPath, queueFilesMutArr[queueIndex]];
|
|
1952
|
+
NSString *queueURL = [NSString stringWithFormat:@"%@/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=%@&country_code=%@&user_id=%@&file_name=%@", clientUrl, clientId, countryCode, userID, queueFilesMutArr[queueIndex]];
|
|
1953
|
+
[self sendFilesToServer:queueFilesPath fileName:queueFilesMutArr[queueIndex] requestURL:queueURL];
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
} else {
|
|
1957
|
+
NSLog(@"No database directory found at the path..");
|
|
1765
1958
|
}
|
|
1766
1959
|
}
|
|
1767
1960
|
} else {
|
|
1768
|
-
NSLog(@"No
|
|
1961
|
+
NSLog(@"No Internet connection..");
|
|
1769
1962
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1963
|
+
}else{
|
|
1964
|
+
NSLog(@"Error in reading files: %@", error);
|
|
1965
|
+
}
|
|
1966
|
+
}else {
|
|
1967
|
+
NSLog(@"File not available at the path..");
|
|
1773
1968
|
}
|
|
1774
1969
|
}];
|
|
1775
1970
|
}
|
|
@@ -1872,7 +2067,7 @@
|
|
|
1872
2067
|
@try {
|
|
1873
2068
|
NSError *jsonError;
|
|
1874
2069
|
NSString *getKeyApsx = [NSString stringWithFormat:@"%@/common/components/Keys/RetrieveKey.aspx", clientUrl];
|
|
1875
|
-
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\"}",clientId, countryCode];
|
|
2070
|
+
NSString *keyContent = [NSString stringWithFormat:@"{\"client_id\":\"%@\",\"country_code\":\"%@\",\"purposeCode\":\"mobile_address_store\",\"version\":\"doubleo\"}",clientId, countryCode];
|
|
1876
2071
|
NSMutableURLRequest *authRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:getKeyApsx]];
|
|
1877
2072
|
[authRequest setValue:@"text/json" forHTTPHeaderField:@"Content-type"];
|
|
1878
2073
|
[authRequest setHTTPMethod : @"POST"];
|
|
@@ -2360,6 +2555,36 @@
|
|
|
2360
2555
|
return app_uuid;
|
|
2361
2556
|
}
|
|
2362
2557
|
|
|
2558
|
+
- (void)getMyAccountsData:(CDVInvokedUrlCommand *)command{
|
|
2559
|
+
NSMutableDictionary * dict = [[command arguments] objectAtIndex:0];
|
|
2560
|
+
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
2561
|
+
NSString *folderPath = [NSString stringWithFormat:@"%@/%@", dir, dict[@"folderPath"]];
|
|
2562
|
+
CDVPluginResult* pluginResult = nil;
|
|
2563
|
+
NSMutableArray* dataArray = [NSMutableArray array];
|
|
2564
|
+
NSError* error = nil;
|
|
2565
|
+
NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
2566
|
+
if ([fileManager fileExistsAtPath:folderPath isDirectory:nil]) {
|
|
2567
|
+
NSArray* files = [fileManager contentsOfDirectoryAtPath:folderPath error:&error];
|
|
2568
|
+
if (files) {
|
|
2569
|
+
for (NSString* fileName in files) {
|
|
2570
|
+
if ([fileName.pathExtension isEqualToString:@"json"]) {
|
|
2571
|
+
NSString* filePath = [folderPath stringByAppendingPathComponent:fileName];
|
|
2572
|
+
NSData* jsonData = [NSData dataWithContentsOfFile:filePath];
|
|
2573
|
+
if (jsonData) {
|
|
2574
|
+
NSString* jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
2575
|
+
[dataArray addObject:jsonString];
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
} else {
|
|
2580
|
+
NSLog(@"Error reading folder contents: %@", error);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
NSString *jsonArrayString = [NSString stringWithFormat:@"[%@]", [dataArray componentsJoinedByString:@","]];
|
|
2584
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonArrayString];
|
|
2585
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2363
2588
|
- (void)DeviceInfo:(CDVInvokedUrlCommand*)command {
|
|
2364
2589
|
NSString * directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
2365
2590
|
NSLog(@"Documents Path : %@", directory);
|
|
@@ -2453,3 +2678,6 @@
|
|
|
2453
2678
|
}
|
|
2454
2679
|
@end
|
|
2455
2680
|
|
|
2681
|
+
|
|
2682
|
+
|
|
2683
|
+
|