cordova-plugin-appice 2.0.2 → 2.0.3

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.
@@ -1,1068 +1,1068 @@
1
-
2
- #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
3
- @import UserNotifications;
4
- #endif
5
-
6
- #import "AppICEPlugin.h"
7
- #import "AppDelegate+AppICEPlugin.h"
8
-
9
- #import "appICE.h"
10
- #import "appICEUserDetails.h"
11
-
12
-
13
- //#import "SBJson.h"
14
- //#import "ASIHTTPRequest.h"
15
-
16
- NSString *baseUrl;
17
- NSString *postData;
18
- HttpSuccessBlock successBlock;
19
- HttpFailBlock failBlock;
20
- NSDictionary *headers;
21
- int timeout;
22
- BOOL validateCerts;
23
- BOOL isPostRequest;
24
- NSTimeInterval requestTime;
25
-
26
- #define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
27
-
28
-
29
- @implementation AppICEPlugin
30
-
31
- static AppICEPlugin *appice;
32
-
33
- static NSInteger const kNotificationStackSize = 10;
34
- @synthesize notificationCallbackId;
35
- @synthesize notificationStack;
36
-
37
- +(void)load {
38
-
39
- @try {
40
- // Listen for UIApplicationDidFinishLaunchingNotification to get a hold of launchOptions
41
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidFinishLaunchingNotification:) name:UIApplicationDidFinishLaunchingNotification object:nil];
42
-
43
- } @catch (NSException *exception) {
44
- }
45
- }
46
-
47
- +(void)onDidFinishLaunchingNotification:(NSNotification *)notification {
48
- // Init appice
49
-
50
- }
51
-
52
- -(void)handleToken:(NSData *)deviceToken {
53
- @try {
54
- NSLog(@"Apns token : %@", deviceToken);
55
-
56
-
57
- [appICE setTokenInPushNotification:deviceToken];
58
- } @catch (NSException *exception) {
59
- }
60
- }
61
-
62
- -(void)handleTokenError:(NSError *)error {
63
- @try {
64
- NSLog(@"Apns token Error : %@", error.description);
65
- } @catch (NSException *exception) {
66
- }
67
- }
68
-
69
- +(AppICEPlugin*) appice {
70
- return appice;
71
- }
72
-
73
- -(void)pluginInitialize {
74
- [super pluginInitialize];
75
-
76
- @try {
77
- appice = self;
78
-
79
- // Setup keys
80
- NSString *appid = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEAppID"];
81
- NSString *appkey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEAppKey"];
82
- NSString *apikey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEApiKey"];
83
- NSString *appiceDeviceId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEDeviceId"];
84
- NSString *appiceRegion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICERegion"];
85
- NSString *appiceBaseurl = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEBaseUrl"];
86
- NSArray *appicecerts = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICECerts"];
87
- if (appid != nil && appid.length >= 0 && appkey != nil && appkey.length >= 0 && apikey != nil && apikey.length >= 0) {
88
- [appICE setupKeys:appkey withapiKey:apikey withappId:appid otherSdkdeviceId:appiceDeviceId region:appiceRegion baseUrl:appiceBaseurl certficates:appicecerts];
89
- }
90
- } @catch (NSException *exception) {
91
-
92
- } @finally {
93
-
94
- }
95
- }
96
-
97
- -(void)onHandleLocalNotification:(UILocalNotification *)notification {
98
- @try {
99
- UIApplicationState appState = UIApplicationStateActive;
100
- UIApplication *application = [UIApplication sharedApplication];
101
- if ([application respondsToSelector:@selector(applicationState)])
102
- appState = application.applicationState;
103
-
104
- if (appState == UIApplicationStateActive)
105
- {
106
- NSLog(@"stateActive");
107
- }
108
- else
109
- {
110
- NSDictionary* userInfo = [notification userInfo];
111
- // NSLog(@"UserInfo = %@", userInfo);
112
-
113
- // NSString* campid = [[notification userInfo] objectForKey:@"campid"];
114
- // NSLog(@"campid = %@", campid);
115
-
116
- NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
117
- numberOfBadges -=1;
118
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
119
-
120
- //[[appICE sharedInstance] handleclickonpush:userInfo];
121
- [[appICE sharedInstance]handleClickOnPush:userInfo OpenDeepLink:YES];
122
-
123
- [self sendCallback:userInfo];
124
- }
125
-
126
- if (application.applicationState==UIApplicationStateActive)
127
- {
128
- UILocalNotification * notif = (UILocalNotification*) notification;
129
- notif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
130
- //[appICE receiveLocalNotification:notification];
131
- }
132
- } @catch (NSException *exception) {
133
-
134
- } @finally {
135
-
136
- }
137
- }
138
-
139
- -(void)onHandleRemoteUNotification:(NSDictionary *)userInfo {
140
- @try {
141
- BOOL isSilent = [[appICE sharedInstance] isSilentPush:userInfo];
142
- BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
143
- if(appIceServer)
144
- {
145
- [[appICE sharedInstance] pushNotificationReceived:userInfo];
146
-
147
- }
148
-
149
- }
150
- @catch (NSException *exception) {
151
-
152
- } @finally {
153
-
154
- }
155
- }
156
-
157
- -(void)onHandleNotificationUResponse:(NSDictionary *)userInfo {
158
- @try {
159
- NSLog(@"appice - uresponse : %@",userInfo);
160
-
161
- BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
162
- if(appIceServer)
163
- {
164
- [[appICE sharedInstance] handleClickOnPush:userInfo OpenDeepLink:YES];
165
- [self sendCallback:userInfo];
166
-
167
- }
168
- } @catch (NSException *exception) {
169
- NSLog(@"appice - uresponse : %@",exception.description);
170
- } @finally {
171
-
172
- }
173
- }
174
- -(id)sendRequestWithURL:(NSString*)url withPostData:(NSString*)post postType:(BOOL)type {
175
- return [self initWithURL:url withPostData:post withPostType:type];
176
- }
177
- -(id)initWithURL:(NSString*)url withPostData:(NSString*)post withPostType:(BOOL)type {
178
- self = [self init];
179
-
180
- successBlock = NULL;
181
- failBlock = NULL;
182
- headers = NULL;
183
- timeout = -1;
184
- validateCerts = YES;
185
-
186
- baseUrl = url;
187
- postData = post;
188
- isPostRequest = type;
189
-
190
- return self;
191
- }
192
- -(void)setHeaders:(NSDictionary*)header {
193
- headers = header;
194
- }
195
-
196
- -(void)setTimeout:(int)time withCertValidate:(BOOL)validate {
197
- timeout = time;
198
- validateCerts = validate;
199
- }
200
-
201
- -(void)setSuccessBlock:(HttpSuccessBlock)block {
202
- successBlock = block;
203
- }
204
-
205
- -(void)setFailBlock:(HttpFailBlock)block {
206
- failBlock = block;
207
- }
208
- -(void)sendCallback:(NSDictionary *)userInfo {
209
-
210
-
211
- @try {
212
- if (userInfo != NULL&& [userInfo objectForKey:@"data"] != NULL) {
213
- NSDictionary *data = [userInfo objectForKey:@"data"];
214
- NSDictionary *message = [data objectForKey:@"message"];
215
- if (message != NULL && [message objectForKey:@"et"] != NULL) {
216
- NSString *et = [message objectForKey:@"et"];
217
- if (et != NULL
218
- // && [et caseInsensitiveCompare:@"dl"] == NSOrderedSame
219
- ) {
220
- NSMutableDictionary *dpDict = [[NSMutableDictionary alloc] init];
221
- @try {
222
- NSString *url = [message objectForKey:@"eurl"];
223
- if (url != NULL && url.length > 0) {
224
- NSURL *uri = [NSURL URLWithString:url];
225
- if (uri != NULL) {
226
- dpDict = [self getUrlParameters:url];
227
- [dpDict setObject:@"true" forKey:@"tap"];
228
- [dpDict setObject:uri.host forKey:@"host"];
229
- [dpDict setObject:uri.path forKey:@"path"];
230
- }
231
- }
232
- } @catch(NSException *e) {}
233
-
234
- @try {
235
- NSDictionary *cdata = [message objectForKey:@"cdata"];
236
- // NSString *template = [cdata objectForKey:@"template"];
237
- // if (template != NULL
238
- //&& [template isKindOfClass:[NSString class]]
239
- // ) {
240
- NSString *udata = (NSString*) cdata;
241
- if ([udata hasPrefix:@"http://"] || [udata hasPrefix:@"https://"]) {
242
- // cdata contains length text inside url - fetch and process it
243
- NSURL *url = [NSURL URLWithString:[udata stringByAddingPercentEscapesUsingEncoding:
244
- NSASCIIStringEncoding]];
245
- NSString * ur = [NSString stringWithFormat:@"%@",url];
246
- [self sendRequestWithURL:ur withPostData:@"" postType:NO];
247
- [self setTimeout:5 withCertValidate:YES];
248
- [self setHeaders:[NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"Content-Type", nil]];
249
- [self setSuccessBlock:^(int statusCode, NSString *response) {
250
- if (response.length == 0) {
251
- NSLog(@"sendCallback : response coming empty");
252
- }
253
- else{
254
- NSDictionary *jsonObject1 = [NSJSONSerialization JSONObjectWithData:[response dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
255
-
256
- NSLog(@"shailesh res :%@",jsonObject1);
257
- [self fillDicData:jsonObject1 within:dpDict];
258
-
259
- // NSString * cdatastr = [jsonObject1 objectForKey:@"cdata"];
260
- //[dpDict setObject:cdatastr forKey:@"cdata"];
261
- [self sendNotification:dpDict];
262
-
263
-
264
- }
265
- }];
266
- [self setFailBlock:^(NSError *error) {
267
-
268
- NSLog(@"Error in request :%@", [error localizedDescription]);
269
- }];
270
- [self startASyncHttp];
271
- }
272
-
273
- // }
274
- else if (cdata != NULL && [cdata isKindOfClass:[NSDictionary class]]) {
275
- // cdata contains object process encoded data and store in dictionary to be passed to cordova
276
- NSDictionary *jsonObject = (NSDictionary*) cdata;
277
- [self fillDicData:jsonObject within:dpDict];
278
- }
279
-
280
- } @catch(NSException *e) {
281
- NSLog(@"Exception : %@", [e callStackSymbols]);
282
- }
283
- NSLog(@"Appice - sendallback : %@", dpDict);
284
- if (dpDict != NULL) {
285
- //[self sendNotification:dpDict];
286
- }
287
- }
288
- }
289
- }
290
-
291
- } @catch (NSException *exception) {
292
-
293
- } @finally {
294
-
295
- }
296
- }
297
- -(void)startASyncHttp {
298
- @try {
299
- requestTime = [[NSDate date] timeIntervalSince1970];
300
-
301
- NSLog(@"AppICE HTTP Request Time : %f , URL : %@ , Type : %d, PostData : %@ ", requestTime, baseUrl, isPostRequest, postData);
302
-
303
- NSURL *url = [NSURL URLWithString:baseUrl];
304
-
305
- // Create the request.
306
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
307
-
308
- // Set Post data
309
- if (isPostRequest || postData != NULL) {
310
- NSData *requestBodyData = [postData dataUsingEncoding:NSUTF8StringEncoding];
311
- request.HTTPBody = requestBodyData;
312
- }
313
-
314
- // Check request method type
315
- if (isPostRequest)
316
- request.HTTPMethod = @"POST";
317
- else
318
- request.HTTPMethod = @"GET";
319
-
320
- // Set default Auth-Headers
321
- [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"app_id"] forHTTPHeaderField:@"X-AppICE-Auth-AppID"];
322
- [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"app_key"] forHTTPHeaderField:@"X-AppICE-Auth-AppKey"];
323
- [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"api_key"] forHTTPHeaderField:@"X-AppICE-Auth-ApiKey"];
324
- [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"appiceudid"] forHTTPHeaderField:@"X-AppICE-Auth-DeviceId"];
325
- [request setValue:@"" forHTTPHeaderField:@"X-AppICE-Auth-UserId"];
326
-
327
- // Set headers
328
- if (headers != NULL) {
329
- for (id key in headers) {
330
- [request setValue:[headers objectForKey:key] forHTTPHeaderField:key];
331
- }
332
- }
333
-
334
- // Set timeout and validate certificate
335
- if (timeout > 0)
336
- [request setTimeoutInterval:timeout];
337
-
338
- // Create url connection and fire request
339
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
340
-
341
- if (connectionError != NULL) {
342
- NSLog(@"AppICE HTTP Error Time : %f , Error : %@", requestTime, connectionError.description);
343
-
344
- if (failBlock != NULL)
345
- failBlock(connectionError);
346
- }
347
- else {
348
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
349
-
350
- NSString *responseData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
351
- int statusCode = (int) [httpResponse statusCode];
352
-
353
- NSLog(@"AppICE HTTP Response Time : %f , Status : %d , Response : %@ ", requestTime, statusCode, responseData);
354
-
355
- if (successBlock != NULL)
356
- successBlock(statusCode, responseData);
357
- }
358
- }];
359
-
360
- } @catch (NSException *exception) {
361
- NSLog(@"AppICE HTTP Exception Time : %f , Error : %@", requestTime, exception.description);
362
- } @finally {
363
- }
364
- }
365
- -(void) fillDicData:(NSDictionary*)dict within:(NSMutableDictionary*)mutable {
366
- @try {
367
- if (dict != NULL) {
368
- for (id key in dict) {
369
- id value = [dict objectForKey:key];
370
- if (value != NULL && [value isKindOfClass:[NSString class]]){
371
- NSString *svalue = (NSString*) value;
372
- svalue = [svalue stringByRemovingPercentEncoding];
373
- [mutable setObject:svalue forKey:key];
374
- }
375
- else
376
- [mutable setObject:value forKey:key];
377
- }
378
- }
379
- } @catch (NSException *exception) {
380
-
381
- } @finally {
382
-
383
- }
384
- }
385
-
386
- -(NSMutableDictionary *)getUrlParameters:(NSString *)url{
387
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
388
-
389
- @try {
390
- NSArray *justParamsArr = [url componentsSeparatedByString:@"?"];
391
- url = [justParamsArr lastObject];
392
-
393
- for (NSString *param in [url componentsSeparatedByString:@"&"]) {
394
- NSArray *elts = [param componentsSeparatedByString:@"="];
395
- if([elts count] < 2) continue;
396
-
397
- id value = [elts lastObject];
398
- if (value != NULL && [value isKindOfClass:[NSString class]]){
399
- NSString *svalue = (NSString*) value;
400
- svalue = [svalue stringByRemovingPercentEncoding];
401
- [params setObject:svalue forKey:[elts firstObject]];
402
- }
403
- else
404
- [params setObject:[elts lastObject] forKey:[elts firstObject]];
405
- }
406
- } @catch (NSException *exception) {
407
-
408
- } @finally {
409
-
410
- }
411
- return params;
412
- }
413
-
414
- -(void)onHandleOpenURLNotification:(NSURL *)url {
415
-
416
- }
417
-
418
- -(void)onHandleActionForIdentifier:(NSString *)identifier {
419
- @try {
420
- if ([identifier isEqualToString:@"ACTION_ONE"]) {
421
- //[[appICE sharedInstance] handleactionfirstforPUSH];
422
- }
423
- else if ([identifier isEqualToString:@"ACTION_TWO"]) {
424
- // [[appICE sharedInstance] handleactionsecondforPUSH];
425
- }
426
- else if ([identifier isEqualToString:@"ACTION_THREE"]) {
427
- //[[appICE sharedInstance] handleactionthirdforPUSH];
428
- }
429
- } @catch (NSException *exception) {
430
-
431
- } @finally {
432
-
433
- }
434
- }
435
-
436
- #pragma mark - Cordova Methods
437
-
438
- /**
439
- Notification Registration
440
- */
441
- - (void)registerForRemoteNotification {
442
- @try {
443
- if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) {
444
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
445
- center.delegate = [AppDelegate delegate];
446
- [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
447
- if( !error ){
448
- dispatch_async(dispatch_get_main_queue(), ^{
449
- [[UIApplication sharedApplication] registerForRemoteNotifications];
450
- });
451
- }
452
- }];
453
- }
454
- else {
455
- [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
456
- [[UIApplication sharedApplication] registerForRemoteNotifications];
457
- }
458
- } @catch (NSException *exception) {
459
-
460
- } @finally {
461
-
462
- }
463
- }
464
-
465
- -(void)startContext:(CDVInvokedUrlCommand *)command {
466
- @try {
467
- [self.commandDelegate runInBackground:^{
468
- @try {
469
- [self registerForRemoteNotification];
470
-
471
- [[appICE sharedInstance] startContext];
472
-
473
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
474
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
475
- } @catch(NSException *e) {
476
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
477
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
478
- }
479
- }];
480
- } @catch (NSException *exception) {
481
-
482
- } @finally {
483
-
484
- }
485
- }
486
-
487
- -(void)initSdk:(CDVInvokedUrlCommand *)command {
488
- @try {
489
- [self.commandDelegate runInBackground:^{
490
- @try {
491
- NSObject *eventObj = [command argumentAtIndex:0];
492
- NSString *appID = [eventObj valueForKey:@"appID"];
493
- NSString *appKey = [eventObj valueForKey:@"appKey"];
494
- NSString *apiKey = [eventObj valueForKey:@"apiKey"];
495
- NSString *gcmID = [eventObj valueForKey:@"gcmID"];
496
- NSString *region = [eventObj valueForKey:@"region"];
497
- NSString *baseUrl = [eventObj valueForKey:@"baseUrl"];
498
- NSArray *certs = [eventObj valueForKey:@"certs"];
499
- if (appID != nil && appID.length >= 0 && appKey != nil && appKey.length >= 0 && apiKey != nil && apiKey.length >= 0) {
500
-
501
- [appICE setupKeys:appKey withapiKey:apiKey withappId:appID otherSdkdeviceId:gcmID region:region baseUrl:baseUrl certficates:certs];
502
- }
503
-
504
- [self registerForRemoteNotification];
505
-
506
- [[appICE sharedInstance] startContext];
507
-
508
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
509
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
510
- } @catch(NSException *e) {
511
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
512
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
513
- }
514
- }];
515
- } @catch (NSException *exception) {
516
-
517
- } @finally {
518
-
519
- }
520
- }
521
-
522
- -(void)trackTouches:(CDVInvokedUrlCommand *)command {
523
- @try {
524
- [self.commandDelegate runInBackground:^{
525
- @try {
526
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
527
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
528
- } @catch(NSException *e) {
529
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
530
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
531
- }
532
- }];
533
- } @catch (NSException *exception) {
534
-
535
- } @finally {
536
-
537
- }
538
- }
539
-
540
- -(void)trackSwipes:(CDVInvokedUrlCommand *)command {
541
- @try {
542
- [self.commandDelegate runInBackground:^{
543
- @try {
544
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
545
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
546
- } @catch(NSException *e) {
547
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
548
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
549
- }
550
- }];
551
- } @catch (NSException *exception) {
552
-
553
- } @finally {
554
-
555
- }
556
- }
557
-
558
- -(void)trackScreens:(CDVInvokedUrlCommand *)command {
559
- @try {
560
- [self.commandDelegate runInBackground:^{
561
- @try {
562
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
563
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
564
- } @catch(NSException *e) {
565
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
566
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
567
- }
568
- }];
569
- } @catch (NSException *exception) {
570
-
571
- } @finally {
572
-
573
- }
574
- }
575
-
576
- -(void)stopContext:(CDVInvokedUrlCommand *)command {
577
- [self.commandDelegate runInBackground:^{
578
- @try {
579
-
580
- } @catch(NSException *e) {}
581
- }];
582
- }
583
-
584
- -(void)isSemusiSensing:(CDVInvokedUrlCommand *)command {
585
- [self.commandDelegate runInBackground:^{
586
- @try {
587
-
588
- } @catch(NSException *e) {}
589
- }];
590
- }
591
-
592
- -(void)setAsTestDevice:(CDVInvokedUrlCommand *)command {
593
- [self.commandDelegate runInBackground:^{
594
- @try {
595
-
596
- } @catch(NSException *e) {}
597
- }];
598
- }
599
-
600
- -(void)removeAsTestDevice:(CDVInvokedUrlCommand *)command {
601
- [self.commandDelegate runInBackground:^{
602
- @try {
603
-
604
- } @catch(NSException *e) {}
605
- }];
606
- }
607
-
608
- -(void)getIsTestDevice:(CDVInvokedUrlCommand *)command {
609
- [self.commandDelegate runInBackground:^{
610
- @try {
611
-
612
- } @catch(NSException *e) {}
613
- }];
614
- }
615
-
616
- -(void)openPlayServiceUpdate:(CDVInvokedUrlCommand *)command {
617
- [self.commandDelegate runInBackground:^{
618
- @try {
619
-
620
- } @catch(NSException *e) {}
621
- }];
622
- }
623
-
624
- -(void)getSdkVersion:(CDVInvokedUrlCommand *)command {
625
- [self.commandDelegate runInBackground:^{
626
- @try {
627
- NSString *value = [[appICE sharedInstance] getSdkVersion];
628
-
629
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
630
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
631
-
632
- } @catch(NSException *e) {}
633
- }];
634
- }
635
-
636
- -(void)getSdkIntVersion:(CDVInvokedUrlCommand *)command {
637
- [self.commandDelegate runInBackground:^{
638
- @try {
639
-
640
- } @catch(NSException *e) {}
641
- }];
642
- }
643
-
644
- -(void)setDeviceId:(CDVInvokedUrlCommand *)command {
645
- [self.commandDelegate runInBackground:^{
646
- @try {
647
-
648
- } @catch(NSException *e) {}
649
- }];
650
- }
651
-
652
- -(void)getDeviceId:(CDVInvokedUrlCommand *)command {
653
- [self.commandDelegate runInBackground:^{
654
- @try {
655
- NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"appiceudid"];
656
-
657
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
658
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
659
- } @catch(NSException *e) {
660
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
661
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
662
- }
663
- }];
664
- }
665
-
666
- -(void)getAndroidId:(CDVInvokedUrlCommand *)command {
667
- [self.commandDelegate runInBackground:^{
668
- @try {
669
-
670
- } @catch(NSException *e) {}
671
- }];
672
- }
673
-
674
- -(void)getAppKey:(CDVInvokedUrlCommand *)command {
675
- [self.commandDelegate runInBackground:^{
676
- @try {
677
-
678
- } @catch(NSException *e) {}
679
- }];
680
- }
681
-
682
- -(void)getApiKey:(CDVInvokedUrlCommand *)command {
683
- [self.commandDelegate runInBackground:^{
684
- @try {
685
-
686
- } @catch(NSException *e) {}
687
- }];
688
- }
689
-
690
- -(void)getAppId:(CDVInvokedUrlCommand *)command {
691
- [self.commandDelegate runInBackground:^{
692
- @try {
693
-
694
- } @catch(NSException *e) {}
695
- }];
696
- }
697
-
698
- -(void)getCurrentContext:(CDVInvokedUrlCommand *)command {
699
- [self.commandDelegate runInBackground:^{
700
- @try {
701
-
702
- } @catch(NSException *e) {}
703
- }];
704
- }
705
-
706
- -(void)setAlias:(CDVInvokedUrlCommand *)command {
707
- [self.commandDelegate runInBackground:^{
708
- @try {
709
- NSObject *eventObj = [command argumentAtIndex:0];
710
- NSString *key = [eventObj valueForKey:@"alias"];
711
- if (key != nil && [key isKindOfClass:[NSString class]]) {
712
- [[appICE sharedInstance] setAlias:key];
713
-
714
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
715
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
716
- }
717
- } @catch(NSException *e) {
718
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
719
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
720
- }
721
- }];
722
- }
723
-
724
- -(void)getAlias:(CDVInvokedUrlCommand *)command {
725
- [self.commandDelegate runInBackground:^{
726
- @try {
727
- NSString *value = [[appICE sharedInstance] getChildId:@"_alias"];
728
-
729
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
730
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
731
- } @catch(NSException *e) {
732
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
733
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
734
- }
735
- }];
736
- }
737
-
738
- -(void)setUser:(CDVInvokedUrlCommand *)command {
739
- [self.commandDelegate runInBackground:^{
740
- @try {
741
- NSObject *eventObj = [command argumentAtIndex:0];
742
- NSString *name = [eventObj valueForKey:@"name"];
743
- NSString *phone = [eventObj valueForKey:@"phone"];
744
- NSString *email = [eventObj valueForKey:@"email"];
745
-
746
- appICEUserDetails *details = [appICEUserDetails sharedUserDetails];
747
- [details setName:name];
748
- [details setPhone:phone];
749
- [details setEmail:email];
750
- //[[appICE sharedInstance] setUser:details];
751
- [[appICE sharedInstance] setUserDetail:details];
752
-
753
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
754
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
755
-
756
- } @catch(NSException *e) {
757
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
758
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
759
- }
760
- }];
761
- }
762
-
763
- -(void)getUser:(CDVInvokedUrlCommand *)command {
764
- [self.commandDelegate runInBackground:^{
765
- @try {
766
-
767
- } @catch(NSException *e) {}
768
- }];
769
- }
770
-
771
- -(void)setChildId:(CDVInvokedUrlCommand *)command {
772
- [self.commandDelegate runInBackground:^{
773
- @try {
774
- NSObject *eventObj = [command argumentAtIndex:0];
775
- NSString *key = [eventObj valueForKey:@"childID"];
776
- if (key != nil && [key isKindOfClass:[NSString class]]) {
777
- [[appICE sharedInstance] setChildId:key];
778
-
779
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
780
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
781
- }
782
- } @catch(NSException *e) {
783
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
784
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
785
- }
786
- }];
787
- }
788
-
789
- -(void)getChildId:(CDVInvokedUrlCommand *)command {
790
- [self.commandDelegate runInBackground:^{
791
- @try {
792
- NSString *value = [[appICE sharedInstance] getChildId:@"_childId"];
793
-
794
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
795
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
796
- } @catch(NSException *e) {
797
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
798
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
799
- }
800
- }];
801
- }
802
-
803
- -(void)setReferrer:(CDVInvokedUrlCommand *)command {
804
- [self.commandDelegate runInBackground:^{
805
- @try {
806
-
807
- } @catch(NSException *e) {}
808
- }];
809
- }
810
-
811
- -(void)getReferrer:(CDVInvokedUrlCommand *)command {
812
- [self.commandDelegate runInBackground:^{
813
- @try {
814
-
815
- } @catch(NSException *e) {}
816
- }];
817
- }
818
-
819
- -(void)setInstallReferrer:(CDVInvokedUrlCommand *)command {
820
- [self.commandDelegate runInBackground:^{
821
- @try {
822
-
823
- } @catch(NSException *e) {}
824
- }];
825
- }
826
-
827
- -(void)getInstallReferrer:(CDVInvokedUrlCommand *)command {
828
- [self.commandDelegate runInBackground:^{
829
- @try {
830
-
831
- } @catch(NSException *e) {}
832
- }];
833
- }
834
-
835
- -(void)setInstaller:(CDVInvokedUrlCommand *)command {
836
- [self.commandDelegate runInBackground:^{
837
- @try {
838
-
839
- } @catch(NSException *e) {}
840
- }];
841
- }
842
-
843
- -(void)getInstaller:(CDVInvokedUrlCommand *)command {
844
- [self.commandDelegate runInBackground:^{
845
- @try {
846
-
847
- } @catch(NSException *e) {}
848
- }];
849
- }
850
-
851
- -(void)getGCMSenderId:(CDVInvokedUrlCommand *)command {
852
- [self.commandDelegate runInBackground:^{
853
- @try {
854
-
855
- } @catch(NSException *e) {}
856
- }];
857
- }
858
-
859
- -(void)getDeviceToken:(CDVInvokedUrlCommand *)command {
860
- [self.commandDelegate runInBackground:^{
861
- @try {
862
- NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviveToken"];
863
-
864
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
865
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
866
- } @catch(NSException *e) {
867
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
868
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
869
- }
870
- }];
871
- }
872
-
873
- -(void)setCustomVariable:(CDVInvokedUrlCommand *)command {
874
- [self.commandDelegate runInBackground:^{
875
- @try{
876
- NSObject *eventObj = [command argumentAtIndex:0];
877
- NSString *key = [eventObj valueForKey:@"key"];
878
- id val = [eventObj valueForKey:@"value"];
879
- if (key != nil && [key isKindOfClass:[NSString class]]) {
880
- if (val != nil && [val isKindOfClass:[NSString class]]) {
881
- [[appICE sharedInstance] setCustomVariable:key withStringValue:(NSString*)val];
882
- }
883
- else if (val != nil && [val isKindOfClass:[NSNumber class]]) {
884
- NSNumber *valNum = (NSNumber*) val;
885
- switch(CFNumberGetType((CFNumberRef)valNum))
886
- {
887
- case kCFNumberIntType:
888
- [[appICE sharedInstance] setCustomVariable:key withIntvalue:[valNum intValue]];
889
- break;
890
- case kCFNumberDoubleType:
891
- [[appICE sharedInstance] setCustomVariable:key withBoolValue:[valNum doubleValue]];
892
- break;
893
- case kCFNumberLongType:
894
- [[appICE sharedInstance] setCustomVariable:key withLongValue:[valNum longValue]];
895
- break;
896
- default:
897
- break;
898
- }
899
- }
900
- }
901
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
902
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
903
- } @catch(NSException *error) {
904
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
905
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
906
- }
907
- }];
908
- }
909
-
910
- -(void)getCustomVariable:(CDVInvokedUrlCommand *)command {
911
- [self.commandDelegate runInBackground:^{
912
- @try {
913
- NSObject *eventObj = [command argumentAtIndex:0];
914
- NSString *key = [eventObj valueForKey:@"key"];
915
- if (key != nil && [key isKindOfClass:[NSString class]]) {
916
- NSString *value = [[appICE sharedInstance] getCustomVariable:key];
917
-
918
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
919
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
920
- }
921
- } @catch(NSException *e) {
922
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
923
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
924
- }
925
- }];
926
- }
927
-
928
- -(void)removeCustomVariable:(CDVInvokedUrlCommand *)command {
929
- [self.commandDelegate runInBackground:^{
930
- @try {
931
- NSObject *eventObj = [command argumentAtIndex:0];
932
- NSString *key = [eventObj valueForKey:@"key"];
933
- if (key != nil && [key isKindOfClass:[NSString class]]) {
934
- [[appICE sharedInstance] removeCustomVariable:key];
935
-
936
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
937
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
938
- }
939
- } @catch(NSException *e) {
940
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
941
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
942
- }
943
- }];
944
- }
945
-
946
- -(void)tagEvent:(CDVInvokedUrlCommand *)command {
947
- [self.commandDelegate runInBackground:^{
948
- @try {
949
- NSObject *eventObj = [command argumentAtIndex:0];
950
- NSString *eventName = [eventObj valueForKey:@"key"];
951
- NSDictionary *eventProps = [eventObj valueForKey:@"data"];
952
- if (eventName != nil && [eventName isKindOfClass:[NSString class]] && eventProps != nil && [eventProps isKindOfClass:[NSDictionary class]]) {
953
- [[appICE sharedInstance] recordEvent:eventName segmentation:eventProps count:1];
954
- }
955
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
956
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
957
- } @catch(NSException *e) {
958
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
959
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
960
- }
961
- }];
962
- }
963
-
964
- -(void)setSmallIcon:(CDVInvokedUrlCommand *)command {
965
- [self.commandDelegate runInBackground:^{
966
- @try {
967
-
968
- } @catch(NSException *e) {}
969
- }];
970
- }
971
-
972
- -(void)setSessionTimeout:(CDVInvokedUrlCommand *)command {
973
- [self.commandDelegate runInBackground:^{
974
- @try {
975
- NSObject *eventObj = [command argumentAtIndex:0];
976
- NSNumber *value = [eventObj valueForKey:@"timeout"];
977
- [[appICE sharedInstance] setSessionTimeout:value.intValue];
978
-
979
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
980
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
981
- } @catch(NSException *e) {}
982
- }];
983
- }
984
-
985
- -(void)getSessionTimeout:(CDVInvokedUrlCommand *)command {
986
- [self.commandDelegate runInBackground:^{
987
- @try {
988
- int value = [[appICE sharedInstance] getSessionTimeout];
989
-
990
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:value];
991
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
992
- } @catch(NSException *e) {}
993
- }];
994
- }
995
-
996
- - (void)onNotificationOpen:(CDVInvokedUrlCommand *)command {
997
- @try {
998
- self.notificationCallbackId = command.callbackId;
999
-
1000
- NSLog(@"Appice setcallback a1");
1001
-
1002
- if (self.notificationStack != nil && [self.notificationStack count]) {
1003
- NSLog(@"Appice setcallback a2");
1004
- for (NSDictionary *userInfo in self.notificationStack) {
1005
- NSLog(@"Appice setcallback a3");
1006
- [self sendNotification:userInfo];
1007
- }
1008
- [self.notificationStack removeAllObjects];
1009
- }
1010
- } @catch (NSException *exception) {
1011
-
1012
- } @finally {
1013
-
1014
- }
1015
- }
1016
-
1017
- -(void)validateIntegration:(CDVInvokedUrlCommand *)command {
1018
- @try {
1019
- [self.commandDelegate runInBackground:^{
1020
- @try {
1021
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1022
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1023
- } @catch(NSException *e) {
1024
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1025
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1026
- }
1027
- }];
1028
- } @catch (NSException *exception) {
1029
-
1030
- } @finally {
1031
-
1032
- }
1033
- }
1034
-
1035
- - (void)sendNotification:(NSDictionary *)userInfo {
1036
- @try {
1037
- NSLog(@"Appice send-notifcallback a1 %@",notificationCallbackId);
1038
- if (self.notificationCallbackId != nil) {
1039
- NSLog(@"Appice send-notifcallback a2");
1040
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userInfo];
1041
- [pluginResult setKeepCallbackAsBool:YES];
1042
- NSLog(@"Appice send-notifcallback a3");
1043
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.notificationCallbackId];
1044
- NSLog(@"Appice send-notifcallback a4");
1045
- } else {
1046
- NSLog(@"Appice send-notifcallback a5");
1047
- if (!self.notificationStack) {
1048
- NSLog(@"Appice send-notifcallback a6");
1049
- self.notificationStack = [[NSMutableArray alloc] init];
1050
- }
1051
- NSLog(@"Appice send-notifcallback a7");
1052
- // stack notifications until a callback has been registered
1053
- [self.notificationStack addObject:userInfo];
1054
-
1055
- if ([self.notificationStack count] >= kNotificationStackSize) {
1056
- [self.notificationStack removeLastObject];
1057
- }
1058
- }
1059
- } @catch (NSException *exception) {
1060
-
1061
- } @finally {
1062
-
1063
- }
1064
- }
1065
-
1066
- @end
1067
-
1068
-
1
+
2
+ #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
3
+ @import UserNotifications;
4
+ #endif
5
+
6
+ #import "AppICEPlugin.h"
7
+ #import "AppDelegate+AppICEPlugin.h"
8
+
9
+ #import "appICE.h"
10
+ #import "appICEUserDetails.h"
11
+
12
+
13
+ //#import "SBJson.h"
14
+ //#import "ASIHTTPRequest.h"
15
+
16
+ NSString *baseUrl;
17
+ NSString *postData;
18
+ HttpSuccessBlock successBlock;
19
+ HttpFailBlock failBlock;
20
+ NSDictionary *headers;
21
+ int timeout;
22
+ BOOL validateCerts;
23
+ BOOL isPostRequest;
24
+ NSTimeInterval requestTime;
25
+
26
+ #define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
27
+
28
+
29
+ @implementation AppICEPlugin
30
+
31
+ static AppICEPlugin *appice;
32
+
33
+ static NSInteger const kNotificationStackSize = 10;
34
+ @synthesize notificationCallbackId;
35
+ @synthesize notificationStack;
36
+
37
+ +(void)load {
38
+
39
+ @try {
40
+ // Listen for UIApplicationDidFinishLaunchingNotification to get a hold of launchOptions
41
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidFinishLaunchingNotification:) name:UIApplicationDidFinishLaunchingNotification object:nil];
42
+
43
+ } @catch (NSException *exception) {
44
+ }
45
+ }
46
+
47
+ +(void)onDidFinishLaunchingNotification:(NSNotification *)notification {
48
+ // Init appice
49
+
50
+ }
51
+
52
+ -(void)handleToken:(NSData *)deviceToken {
53
+ @try {
54
+ NSLog(@"Apns token : %@", deviceToken);
55
+
56
+
57
+ [appICE setTokenInPushNotification:deviceToken];
58
+ } @catch (NSException *exception) {
59
+ }
60
+ }
61
+
62
+ -(void)handleTokenError:(NSError *)error {
63
+ @try {
64
+ NSLog(@"Apns token Error : %@", error.description);
65
+ } @catch (NSException *exception) {
66
+ }
67
+ }
68
+
69
+ +(AppICEPlugin*) appice {
70
+ return appice;
71
+ }
72
+
73
+ -(void)pluginInitialize {
74
+ [super pluginInitialize];
75
+
76
+ @try {
77
+ appice = self;
78
+
79
+ // Setup keys
80
+ NSString *appid = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEAppID"];
81
+ NSString *appkey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEAppKey"];
82
+ NSString *apikey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEApiKey"];
83
+ NSString *appiceDeviceId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEDeviceId"];
84
+ NSString *appiceRegion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICERegion"];
85
+ NSString *appiceBaseurl = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICEBaseUrl"];
86
+ NSArray *appicecerts = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppICECerts"];
87
+ if (appid != nil && appid.length >= 0 && appkey != nil && appkey.length >= 0 && apikey != nil && apikey.length >= 0) {
88
+ [appICE setupKeys:appkey withapiKey:apikey withappId:appid otherSdkdeviceId:appiceDeviceId region:appiceRegion baseUrl:appiceBaseurl certficates:appicecerts];
89
+ }
90
+ } @catch (NSException *exception) {
91
+
92
+ } @finally {
93
+
94
+ }
95
+ }
96
+
97
+ -(void)onHandleLocalNotification:(UILocalNotification *)notification {
98
+ @try {
99
+ UIApplicationState appState = UIApplicationStateActive;
100
+ UIApplication *application = [UIApplication sharedApplication];
101
+ if ([application respondsToSelector:@selector(applicationState)])
102
+ appState = application.applicationState;
103
+
104
+ if (appState == UIApplicationStateActive)
105
+ {
106
+ NSLog(@"stateActive");
107
+ }
108
+ else
109
+ {
110
+ NSDictionary* userInfo = [notification userInfo];
111
+ // NSLog(@"UserInfo = %@", userInfo);
112
+
113
+ // NSString* campid = [[notification userInfo] objectForKey:@"campid"];
114
+ // NSLog(@"campid = %@", campid);
115
+
116
+ NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
117
+ numberOfBadges -=1;
118
+ [[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
119
+
120
+ //[[appICE sharedInstance] handleclickonpush:userInfo];
121
+ [[appICE sharedInstance]handleClickOnPush:userInfo OpenDeepLink:YES];
122
+
123
+ [self sendCallback:userInfo];
124
+ }
125
+
126
+ if (application.applicationState==UIApplicationStateActive)
127
+ {
128
+ UILocalNotification * notif = (UILocalNotification*) notification;
129
+ notif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
130
+ //[appICE receiveLocalNotification:notification];
131
+ }
132
+ } @catch (NSException *exception) {
133
+
134
+ } @finally {
135
+
136
+ }
137
+ }
138
+
139
+ -(void)onHandleRemoteUNotification:(NSDictionary *)userInfo {
140
+ @try {
141
+ BOOL isSilent = [[appICE sharedInstance] isSilentPush:userInfo];
142
+ BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
143
+ if(appIceServer)
144
+ {
145
+ [[appICE sharedInstance] pushNotificationReceived:userInfo];
146
+
147
+ }
148
+
149
+ }
150
+ @catch (NSException *exception) {
151
+
152
+ } @finally {
153
+
154
+ }
155
+ }
156
+
157
+ -(void)onHandleNotificationUResponse:(NSDictionary *)userInfo {
158
+ @try {
159
+ NSLog(@"appice - uresponse : %@",userInfo);
160
+
161
+ BOOL appIceServer = [[appICE sharedInstance] isAppICENotification:userInfo];
162
+ if(appIceServer)
163
+ {
164
+ [[appICE sharedInstance] handleClickOnPush:userInfo OpenDeepLink:YES];
165
+ [self sendCallback:userInfo];
166
+
167
+ }
168
+ } @catch (NSException *exception) {
169
+ NSLog(@"appice - uresponse : %@",exception.description);
170
+ } @finally {
171
+
172
+ }
173
+ }
174
+ -(id)sendRequestWithURL:(NSString*)url withPostData:(NSString*)post postType:(BOOL)type {
175
+ return [self initWithURL:url withPostData:post withPostType:type];
176
+ }
177
+ -(id)initWithURL:(NSString*)url withPostData:(NSString*)post withPostType:(BOOL)type {
178
+ self = [self init];
179
+
180
+ successBlock = NULL;
181
+ failBlock = NULL;
182
+ headers = NULL;
183
+ timeout = -1;
184
+ validateCerts = YES;
185
+
186
+ baseUrl = url;
187
+ postData = post;
188
+ isPostRequest = type;
189
+
190
+ return self;
191
+ }
192
+ -(void)setHeaders:(NSDictionary*)header {
193
+ headers = header;
194
+ }
195
+
196
+ -(void)setTimeout:(int)time withCertValidate:(BOOL)validate {
197
+ timeout = time;
198
+ validateCerts = validate;
199
+ }
200
+
201
+ -(void)setSuccessBlock:(HttpSuccessBlock)block {
202
+ successBlock = block;
203
+ }
204
+
205
+ -(void)setFailBlock:(HttpFailBlock)block {
206
+ failBlock = block;
207
+ }
208
+ -(void)sendCallback:(NSDictionary *)userInfo {
209
+
210
+
211
+ @try {
212
+ if (userInfo != NULL&& [userInfo objectForKey:@"data"] != NULL) {
213
+ NSDictionary *data = [userInfo objectForKey:@"data"];
214
+ NSDictionary *message = [data objectForKey:@"message"];
215
+ if (message != NULL && [message objectForKey:@"et"] != NULL) {
216
+ NSString *et = [message objectForKey:@"et"];
217
+ if (et != NULL
218
+ // && [et caseInsensitiveCompare:@"dl"] == NSOrderedSame
219
+ ) {
220
+ NSMutableDictionary *dpDict = [[NSMutableDictionary alloc] init];
221
+ @try {
222
+ NSString *url = [message objectForKey:@"eurl"];
223
+ if (url != NULL && url.length > 0) {
224
+ NSURL *uri = [NSURL URLWithString:url];
225
+ if (uri != NULL) {
226
+ dpDict = [self getUrlParameters:url];
227
+ [dpDict setObject:@"true" forKey:@"tap"];
228
+ [dpDict setObject:uri.host forKey:@"host"];
229
+ [dpDict setObject:uri.path forKey:@"path"];
230
+ }
231
+ }
232
+ } @catch(NSException *e) {}
233
+
234
+ @try {
235
+ NSDictionary *cdata = [message objectForKey:@"cdata"];
236
+ // NSString *template = [cdata objectForKey:@"template"];
237
+ // if (template != NULL
238
+ //&& [template isKindOfClass:[NSString class]]
239
+ // ) {
240
+ NSString *udata = (NSString*) cdata;
241
+ if ([udata hasPrefix:@"http://"] || [udata hasPrefix:@"https://"]) {
242
+ // cdata contains length text inside url - fetch and process it
243
+ NSURL *url = [NSURL URLWithString:[udata stringByAddingPercentEscapesUsingEncoding:
244
+ NSASCIIStringEncoding]];
245
+ NSString * ur = [NSString stringWithFormat:@"%@",url];
246
+ [self sendRequestWithURL:ur withPostData:@"" postType:NO];
247
+ [self setTimeout:5 withCertValidate:YES];
248
+ [self setHeaders:[NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"Content-Type", nil]];
249
+ [self setSuccessBlock:^(int statusCode, NSString *response) {
250
+ if (response.length == 0) {
251
+ NSLog(@"sendCallback : response coming empty");
252
+ }
253
+ else{
254
+ NSDictionary *jsonObject1 = [NSJSONSerialization JSONObjectWithData:[response dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
255
+
256
+ NSLog(@"shailesh res :%@",jsonObject1);
257
+ [self fillDicData:jsonObject1 within:dpDict];
258
+
259
+ // NSString * cdatastr = [jsonObject1 objectForKey:@"cdata"];
260
+ //[dpDict setObject:cdatastr forKey:@"cdata"];
261
+ [self sendNotification:dpDict];
262
+
263
+
264
+ }
265
+ }];
266
+ [self setFailBlock:^(NSError *error) {
267
+
268
+ NSLog(@"Error in request :%@", [error localizedDescription]);
269
+ }];
270
+ [self startASyncHttp];
271
+ }
272
+
273
+ // }
274
+ else if (cdata != NULL && [cdata isKindOfClass:[NSDictionary class]]) {
275
+ // cdata contains object process encoded data and store in dictionary to be passed to cordova
276
+ NSDictionary *jsonObject = (NSDictionary*) cdata;
277
+ [self fillDicData:jsonObject within:dpDict];
278
+ }
279
+
280
+ } @catch(NSException *e) {
281
+ NSLog(@"Exception : %@", [e callStackSymbols]);
282
+ }
283
+ NSLog(@"Appice - sendallback : %@", dpDict);
284
+ if (dpDict != NULL) {
285
+ //[self sendNotification:dpDict];
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ } @catch (NSException *exception) {
292
+
293
+ } @finally {
294
+
295
+ }
296
+ }
297
+ -(void)startASyncHttp {
298
+ @try {
299
+ requestTime = [[NSDate date] timeIntervalSince1970];
300
+
301
+ NSLog(@"AppICE HTTP Request Time : %f , URL : %@ , Type : %d, PostData : %@ ", requestTime, baseUrl, isPostRequest, postData);
302
+
303
+ NSURL *url = [NSURL URLWithString:baseUrl];
304
+
305
+ // Create the request.
306
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
307
+
308
+ // Set Post data
309
+ if (isPostRequest || postData != NULL) {
310
+ NSData *requestBodyData = [postData dataUsingEncoding:NSUTF8StringEncoding];
311
+ request.HTTPBody = requestBodyData;
312
+ }
313
+
314
+ // Check request method type
315
+ if (isPostRequest)
316
+ request.HTTPMethod = @"POST";
317
+ else
318
+ request.HTTPMethod = @"GET";
319
+
320
+ // Set default Auth-Headers
321
+ [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"app_id"] forHTTPHeaderField:@"X-AppICE-Auth-AppID"];
322
+ [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"app_key"] forHTTPHeaderField:@"X-AppICE-Auth-AppKey"];
323
+ [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"api_key"] forHTTPHeaderField:@"X-AppICE-Auth-ApiKey"];
324
+ [request setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"appiceudid"] forHTTPHeaderField:@"X-AppICE-Auth-DeviceId"];
325
+ [request setValue:@"" forHTTPHeaderField:@"X-AppICE-Auth-UserId"];
326
+
327
+ // Set headers
328
+ if (headers != NULL) {
329
+ for (id key in headers) {
330
+ [request setValue:[headers objectForKey:key] forHTTPHeaderField:key];
331
+ }
332
+ }
333
+
334
+ // Set timeout and validate certificate
335
+ if (timeout > 0)
336
+ [request setTimeoutInterval:timeout];
337
+
338
+ // Create url connection and fire request
339
+ [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
340
+
341
+ if (connectionError != NULL) {
342
+ NSLog(@"AppICE HTTP Error Time : %f , Error : %@", requestTime, connectionError.description);
343
+
344
+ if (failBlock != NULL)
345
+ failBlock(connectionError);
346
+ }
347
+ else {
348
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
349
+
350
+ NSString *responseData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
351
+ int statusCode = (int) [httpResponse statusCode];
352
+
353
+ NSLog(@"AppICE HTTP Response Time : %f , Status : %d , Response : %@ ", requestTime, statusCode, responseData);
354
+
355
+ if (successBlock != NULL)
356
+ successBlock(statusCode, responseData);
357
+ }
358
+ }];
359
+
360
+ } @catch (NSException *exception) {
361
+ NSLog(@"AppICE HTTP Exception Time : %f , Error : %@", requestTime, exception.description);
362
+ } @finally {
363
+ }
364
+ }
365
+ -(void) fillDicData:(NSDictionary*)dict within:(NSMutableDictionary*)mutable {
366
+ @try {
367
+ if (dict != NULL) {
368
+ for (id key in dict) {
369
+ id value = [dict objectForKey:key];
370
+ if (value != NULL && [value isKindOfClass:[NSString class]]){
371
+ NSString *svalue = (NSString*) value;
372
+ svalue = [svalue stringByRemovingPercentEncoding];
373
+ [mutable setObject:svalue forKey:key];
374
+ }
375
+ else
376
+ [mutable setObject:value forKey:key];
377
+ }
378
+ }
379
+ } @catch (NSException *exception) {
380
+
381
+ } @finally {
382
+
383
+ }
384
+ }
385
+
386
+ -(NSMutableDictionary *)getUrlParameters:(NSString *)url{
387
+ NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
388
+
389
+ @try {
390
+ NSArray *justParamsArr = [url componentsSeparatedByString:@"?"];
391
+ url = [justParamsArr lastObject];
392
+
393
+ for (NSString *param in [url componentsSeparatedByString:@"&"]) {
394
+ NSArray *elts = [param componentsSeparatedByString:@"="];
395
+ if([elts count] < 2) continue;
396
+
397
+ id value = [elts lastObject];
398
+ if (value != NULL && [value isKindOfClass:[NSString class]]){
399
+ NSString *svalue = (NSString*) value;
400
+ svalue = [svalue stringByRemovingPercentEncoding];
401
+ [params setObject:svalue forKey:[elts firstObject]];
402
+ }
403
+ else
404
+ [params setObject:[elts lastObject] forKey:[elts firstObject]];
405
+ }
406
+ } @catch (NSException *exception) {
407
+
408
+ } @finally {
409
+
410
+ }
411
+ return params;
412
+ }
413
+
414
+ -(void)onHandleOpenURLNotification:(NSURL *)url {
415
+
416
+ }
417
+
418
+ -(void)onHandleActionForIdentifier:(NSString *)identifier {
419
+ @try {
420
+ if ([identifier isEqualToString:@"ACTION_ONE"]) {
421
+ //[[appICE sharedInstance] handleactionfirstforPUSH];
422
+ }
423
+ else if ([identifier isEqualToString:@"ACTION_TWO"]) {
424
+ // [[appICE sharedInstance] handleactionsecondforPUSH];
425
+ }
426
+ else if ([identifier isEqualToString:@"ACTION_THREE"]) {
427
+ //[[appICE sharedInstance] handleactionthirdforPUSH];
428
+ }
429
+ } @catch (NSException *exception) {
430
+
431
+ } @finally {
432
+
433
+ }
434
+ }
435
+
436
+ #pragma mark - Cordova Methods
437
+
438
+ /**
439
+ Notification Registration
440
+ */
441
+ - (void)registerForRemoteNotification {
442
+ @try {
443
+ if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) {
444
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
445
+ center.delegate = [AppDelegate delegate];
446
+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
447
+ if( !error ){
448
+ dispatch_async(dispatch_get_main_queue(), ^{
449
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
450
+ });
451
+ }
452
+ }];
453
+ }
454
+ else {
455
+ [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
456
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
457
+ }
458
+ } @catch (NSException *exception) {
459
+
460
+ } @finally {
461
+
462
+ }
463
+ }
464
+
465
+ -(void)startContext:(CDVInvokedUrlCommand *)command {
466
+ @try {
467
+ [self.commandDelegate runInBackground:^{
468
+ @try {
469
+ [self registerForRemoteNotification];
470
+
471
+ [[appICE sharedInstance] startContext];
472
+
473
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
474
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
475
+ } @catch(NSException *e) {
476
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
477
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
478
+ }
479
+ }];
480
+ } @catch (NSException *exception) {
481
+
482
+ } @finally {
483
+
484
+ }
485
+ }
486
+
487
+ -(void)initSdk:(CDVInvokedUrlCommand *)command {
488
+ @try {
489
+ [self.commandDelegate runInBackground:^{
490
+ @try {
491
+ NSObject *eventObj = [command argumentAtIndex:0];
492
+ NSString *appID = [eventObj valueForKey:@"appID"];
493
+ NSString *appKey = [eventObj valueForKey:@"appKey"];
494
+ NSString *apiKey = [eventObj valueForKey:@"apiKey"];
495
+ NSString *gcmID = [eventObj valueForKey:@"gcmID"];
496
+ NSString *region = [eventObj valueForKey:@"region"];
497
+ NSString *baseUrl = [eventObj valueForKey:@"baseUrl"];
498
+ NSArray *certs = [eventObj valueForKey:@"certs"];
499
+ if (appID != nil && appID.length >= 0 && appKey != nil && appKey.length >= 0 && apiKey != nil && apiKey.length >= 0) {
500
+
501
+ [appICE setupKeys:appKey withapiKey:apiKey withappId:appID otherSdkdeviceId:gcmID region:region baseUrl:baseUrl certficates:certs];
502
+ }
503
+
504
+ [self registerForRemoteNotification];
505
+
506
+ [[appICE sharedInstance] startContext];
507
+
508
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
509
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
510
+ } @catch(NSException *e) {
511
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
512
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
513
+ }
514
+ }];
515
+ } @catch (NSException *exception) {
516
+
517
+ } @finally {
518
+
519
+ }
520
+ }
521
+
522
+ -(void)trackTouches:(CDVInvokedUrlCommand *)command {
523
+ @try {
524
+ [self.commandDelegate runInBackground:^{
525
+ @try {
526
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
527
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
528
+ } @catch(NSException *e) {
529
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
530
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
531
+ }
532
+ }];
533
+ } @catch (NSException *exception) {
534
+
535
+ } @finally {
536
+
537
+ }
538
+ }
539
+
540
+ -(void)trackSwipes:(CDVInvokedUrlCommand *)command {
541
+ @try {
542
+ [self.commandDelegate runInBackground:^{
543
+ @try {
544
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
545
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
546
+ } @catch(NSException *e) {
547
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
548
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
549
+ }
550
+ }];
551
+ } @catch (NSException *exception) {
552
+
553
+ } @finally {
554
+
555
+ }
556
+ }
557
+
558
+ -(void)trackScreens:(CDVInvokedUrlCommand *)command {
559
+ @try {
560
+ [self.commandDelegate runInBackground:^{
561
+ @try {
562
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
563
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
564
+ } @catch(NSException *e) {
565
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
566
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
567
+ }
568
+ }];
569
+ } @catch (NSException *exception) {
570
+
571
+ } @finally {
572
+
573
+ }
574
+ }
575
+
576
+ -(void)stopContext:(CDVInvokedUrlCommand *)command {
577
+ [self.commandDelegate runInBackground:^{
578
+ @try {
579
+
580
+ } @catch(NSException *e) {}
581
+ }];
582
+ }
583
+
584
+ -(void)isSemusiSensing:(CDVInvokedUrlCommand *)command {
585
+ [self.commandDelegate runInBackground:^{
586
+ @try {
587
+
588
+ } @catch(NSException *e) {}
589
+ }];
590
+ }
591
+
592
+ -(void)setAsTestDevice:(CDVInvokedUrlCommand *)command {
593
+ [self.commandDelegate runInBackground:^{
594
+ @try {
595
+
596
+ } @catch(NSException *e) {}
597
+ }];
598
+ }
599
+
600
+ -(void)removeAsTestDevice:(CDVInvokedUrlCommand *)command {
601
+ [self.commandDelegate runInBackground:^{
602
+ @try {
603
+
604
+ } @catch(NSException *e) {}
605
+ }];
606
+ }
607
+
608
+ -(void)getIsTestDevice:(CDVInvokedUrlCommand *)command {
609
+ [self.commandDelegate runInBackground:^{
610
+ @try {
611
+
612
+ } @catch(NSException *e) {}
613
+ }];
614
+ }
615
+
616
+ -(void)openPlayServiceUpdate:(CDVInvokedUrlCommand *)command {
617
+ [self.commandDelegate runInBackground:^{
618
+ @try {
619
+
620
+ } @catch(NSException *e) {}
621
+ }];
622
+ }
623
+
624
+ -(void)getSdkVersion:(CDVInvokedUrlCommand *)command {
625
+ [self.commandDelegate runInBackground:^{
626
+ @try {
627
+ NSString *value = [[appICE sharedInstance] getSdkVersion];
628
+
629
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
630
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
631
+
632
+ } @catch(NSException *e) {}
633
+ }];
634
+ }
635
+
636
+ -(void)getSdkIntVersion:(CDVInvokedUrlCommand *)command {
637
+ [self.commandDelegate runInBackground:^{
638
+ @try {
639
+
640
+ } @catch(NSException *e) {}
641
+ }];
642
+ }
643
+
644
+ -(void)setDeviceId:(CDVInvokedUrlCommand *)command {
645
+ [self.commandDelegate runInBackground:^{
646
+ @try {
647
+
648
+ } @catch(NSException *e) {}
649
+ }];
650
+ }
651
+
652
+ -(void)getDeviceId:(CDVInvokedUrlCommand *)command {
653
+ [self.commandDelegate runInBackground:^{
654
+ @try {
655
+ NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"appiceudid"];
656
+
657
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
658
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
659
+ } @catch(NSException *e) {
660
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
661
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
662
+ }
663
+ }];
664
+ }
665
+
666
+ -(void)getAndroidId:(CDVInvokedUrlCommand *)command {
667
+ [self.commandDelegate runInBackground:^{
668
+ @try {
669
+
670
+ } @catch(NSException *e) {}
671
+ }];
672
+ }
673
+
674
+ -(void)getAppKey:(CDVInvokedUrlCommand *)command {
675
+ [self.commandDelegate runInBackground:^{
676
+ @try {
677
+
678
+ } @catch(NSException *e) {}
679
+ }];
680
+ }
681
+
682
+ -(void)getApiKey:(CDVInvokedUrlCommand *)command {
683
+ [self.commandDelegate runInBackground:^{
684
+ @try {
685
+
686
+ } @catch(NSException *e) {}
687
+ }];
688
+ }
689
+
690
+ -(void)getAppId:(CDVInvokedUrlCommand *)command {
691
+ [self.commandDelegate runInBackground:^{
692
+ @try {
693
+
694
+ } @catch(NSException *e) {}
695
+ }];
696
+ }
697
+
698
+ -(void)getCurrentContext:(CDVInvokedUrlCommand *)command {
699
+ [self.commandDelegate runInBackground:^{
700
+ @try {
701
+
702
+ } @catch(NSException *e) {}
703
+ }];
704
+ }
705
+
706
+ -(void)setAlias:(CDVInvokedUrlCommand *)command {
707
+ [self.commandDelegate runInBackground:^{
708
+ @try {
709
+ NSObject *eventObj = [command argumentAtIndex:0];
710
+ NSString *key = [eventObj valueForKey:@"alias"];
711
+ if (key != nil && [key isKindOfClass:[NSString class]]) {
712
+ [[appICE sharedInstance] setAlias:key];
713
+
714
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
715
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
716
+ }
717
+ } @catch(NSException *e) {
718
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
719
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
720
+ }
721
+ }];
722
+ }
723
+
724
+ -(void)getAlias:(CDVInvokedUrlCommand *)command {
725
+ [self.commandDelegate runInBackground:^{
726
+ @try {
727
+ NSString *value = [[appICE sharedInstance] getChildId:@"_alias"];
728
+
729
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
730
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
731
+ } @catch(NSException *e) {
732
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
733
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
734
+ }
735
+ }];
736
+ }
737
+
738
+ -(void)setUser:(CDVInvokedUrlCommand *)command {
739
+ [self.commandDelegate runInBackground:^{
740
+ @try {
741
+ NSObject *eventObj = [command argumentAtIndex:0];
742
+ NSString *name = [eventObj valueForKey:@"name"];
743
+ NSString *phone = [eventObj valueForKey:@"phone"];
744
+ NSString *email = [eventObj valueForKey:@"email"];
745
+
746
+ appICEUserDetails *details = [appICEUserDetails sharedUserDetails];
747
+ [details setName:name];
748
+ [details setPhone:phone];
749
+ [details setEmail:email];
750
+ //[[appICE sharedInstance] setUser:details];
751
+ [[appICE sharedInstance] setUserDetail:details];
752
+
753
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
754
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
755
+
756
+ } @catch(NSException *e) {
757
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
758
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
759
+ }
760
+ }];
761
+ }
762
+
763
+ -(void)getUser:(CDVInvokedUrlCommand *)command {
764
+ [self.commandDelegate runInBackground:^{
765
+ @try {
766
+
767
+ } @catch(NSException *e) {}
768
+ }];
769
+ }
770
+
771
+ -(void)setChildId:(CDVInvokedUrlCommand *)command {
772
+ [self.commandDelegate runInBackground:^{
773
+ @try {
774
+ NSObject *eventObj = [command argumentAtIndex:0];
775
+ NSString *key = [eventObj valueForKey:@"childID"];
776
+ if (key != nil && [key isKindOfClass:[NSString class]]) {
777
+ [[appICE sharedInstance] setChildId:key];
778
+
779
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
780
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
781
+ }
782
+ } @catch(NSException *e) {
783
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
784
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
785
+ }
786
+ }];
787
+ }
788
+
789
+ -(void)getChildId:(CDVInvokedUrlCommand *)command {
790
+ [self.commandDelegate runInBackground:^{
791
+ @try {
792
+ NSString *value = [[appICE sharedInstance] getChildId:@"_childId"];
793
+
794
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
795
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
796
+ } @catch(NSException *e) {
797
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
798
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
799
+ }
800
+ }];
801
+ }
802
+
803
+ -(void)setReferrer:(CDVInvokedUrlCommand *)command {
804
+ [self.commandDelegate runInBackground:^{
805
+ @try {
806
+
807
+ } @catch(NSException *e) {}
808
+ }];
809
+ }
810
+
811
+ -(void)getReferrer:(CDVInvokedUrlCommand *)command {
812
+ [self.commandDelegate runInBackground:^{
813
+ @try {
814
+
815
+ } @catch(NSException *e) {}
816
+ }];
817
+ }
818
+
819
+ -(void)setInstallReferrer:(CDVInvokedUrlCommand *)command {
820
+ [self.commandDelegate runInBackground:^{
821
+ @try {
822
+
823
+ } @catch(NSException *e) {}
824
+ }];
825
+ }
826
+
827
+ -(void)getInstallReferrer:(CDVInvokedUrlCommand *)command {
828
+ [self.commandDelegate runInBackground:^{
829
+ @try {
830
+
831
+ } @catch(NSException *e) {}
832
+ }];
833
+ }
834
+
835
+ -(void)setInstaller:(CDVInvokedUrlCommand *)command {
836
+ [self.commandDelegate runInBackground:^{
837
+ @try {
838
+
839
+ } @catch(NSException *e) {}
840
+ }];
841
+ }
842
+
843
+ -(void)getInstaller:(CDVInvokedUrlCommand *)command {
844
+ [self.commandDelegate runInBackground:^{
845
+ @try {
846
+
847
+ } @catch(NSException *e) {}
848
+ }];
849
+ }
850
+
851
+ -(void)getGCMSenderId:(CDVInvokedUrlCommand *)command {
852
+ [self.commandDelegate runInBackground:^{
853
+ @try {
854
+
855
+ } @catch(NSException *e) {}
856
+ }];
857
+ }
858
+
859
+ -(void)getDeviceToken:(CDVInvokedUrlCommand *)command {
860
+ [self.commandDelegate runInBackground:^{
861
+ @try {
862
+ NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviveToken"];
863
+
864
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
865
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
866
+ } @catch(NSException *e) {
867
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
868
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
869
+ }
870
+ }];
871
+ }
872
+
873
+ -(void)setCustomVariable:(CDVInvokedUrlCommand *)command {
874
+ [self.commandDelegate runInBackground:^{
875
+ @try{
876
+ NSObject *eventObj = [command argumentAtIndex:0];
877
+ NSString *key = [eventObj valueForKey:@"key"];
878
+ id val = [eventObj valueForKey:@"value"];
879
+ if (key != nil && [key isKindOfClass:[NSString class]]) {
880
+ if (val != nil && [val isKindOfClass:[NSString class]]) {
881
+ [[appICE sharedInstance] setCustomVariable:key withStringValue:(NSString*)val];
882
+ }
883
+ else if (val != nil && [val isKindOfClass:[NSNumber class]]) {
884
+ NSNumber *valNum = (NSNumber*) val;
885
+ switch(CFNumberGetType((CFNumberRef)valNum))
886
+ {
887
+ case kCFNumberIntType:
888
+ [[appICE sharedInstance] setCustomVariable:key withIntvalue:[valNum intValue]];
889
+ break;
890
+ case kCFNumberDoubleType:
891
+ [[appICE sharedInstance] setCustomVariable:key withBoolValue:[valNum doubleValue]];
892
+ break;
893
+ case kCFNumberLongType:
894
+ [[appICE sharedInstance] setCustomVariable:key withLongValue:[valNum longValue]];
895
+ break;
896
+ default:
897
+ break;
898
+ }
899
+ }
900
+ }
901
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
902
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
903
+ } @catch(NSException *error) {
904
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
905
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
906
+ }
907
+ }];
908
+ }
909
+
910
+ -(void)getCustomVariable:(CDVInvokedUrlCommand *)command {
911
+ [self.commandDelegate runInBackground:^{
912
+ @try {
913
+ NSObject *eventObj = [command argumentAtIndex:0];
914
+ NSString *key = [eventObj valueForKey:@"key"];
915
+ if (key != nil && [key isKindOfClass:[NSString class]]) {
916
+ NSString *value = [[appICE sharedInstance] getCustomVariable:key];
917
+
918
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
919
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
920
+ }
921
+ } @catch(NSException *e) {
922
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
923
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
924
+ }
925
+ }];
926
+ }
927
+
928
+ -(void)removeCustomVariable:(CDVInvokedUrlCommand *)command {
929
+ [self.commandDelegate runInBackground:^{
930
+ @try {
931
+ NSObject *eventObj = [command argumentAtIndex:0];
932
+ NSString *key = [eventObj valueForKey:@"key"];
933
+ if (key != nil && [key isKindOfClass:[NSString class]]) {
934
+ [[appICE sharedInstance] removeCustomVariable:key];
935
+
936
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
937
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
938
+ }
939
+ } @catch(NSException *e) {
940
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
941
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
942
+ }
943
+ }];
944
+ }
945
+
946
+ -(void)tagEvent:(CDVInvokedUrlCommand *)command {
947
+ [self.commandDelegate runInBackground:^{
948
+ @try {
949
+ NSObject *eventObj = [command argumentAtIndex:0];
950
+ NSString *eventName = [eventObj valueForKey:@"key"];
951
+ NSDictionary *eventProps = [eventObj valueForKey:@"data"];
952
+ if (eventName != nil && [eventName isKindOfClass:[NSString class]] && eventProps != nil && [eventProps isKindOfClass:[NSDictionary class]]) {
953
+ [[appICE sharedInstance] recordEvent:eventName segmentation:eventProps count:1];
954
+ }
955
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
956
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
957
+ } @catch(NSException *e) {
958
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
959
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
960
+ }
961
+ }];
962
+ }
963
+
964
+ -(void)setSmallIcon:(CDVInvokedUrlCommand *)command {
965
+ [self.commandDelegate runInBackground:^{
966
+ @try {
967
+
968
+ } @catch(NSException *e) {}
969
+ }];
970
+ }
971
+
972
+ -(void)setSessionTimeout:(CDVInvokedUrlCommand *)command {
973
+ [self.commandDelegate runInBackground:^{
974
+ @try {
975
+ NSObject *eventObj = [command argumentAtIndex:0];
976
+ NSNumber *value = [eventObj valueForKey:@"timeout"];
977
+ [[appICE sharedInstance] setSessionTimeout:value.intValue];
978
+
979
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
980
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
981
+ } @catch(NSException *e) {}
982
+ }];
983
+ }
984
+
985
+ -(void)getSessionTimeout:(CDVInvokedUrlCommand *)command {
986
+ [self.commandDelegate runInBackground:^{
987
+ @try {
988
+ int value = [[appICE sharedInstance] getSessionTimeout];
989
+
990
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:value];
991
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
992
+ } @catch(NSException *e) {}
993
+ }];
994
+ }
995
+
996
+ - (void)onNotificationOpen:(CDVInvokedUrlCommand *)command {
997
+ @try {
998
+ self.notificationCallbackId = command.callbackId;
999
+
1000
+ NSLog(@"Appice setcallback a1");
1001
+
1002
+ if (self.notificationStack != nil && [self.notificationStack count]) {
1003
+ NSLog(@"Appice setcallback a2");
1004
+ for (NSDictionary *userInfo in self.notificationStack) {
1005
+ NSLog(@"Appice setcallback a3");
1006
+ [self sendNotification:userInfo];
1007
+ }
1008
+ [self.notificationStack removeAllObjects];
1009
+ }
1010
+ } @catch (NSException *exception) {
1011
+
1012
+ } @finally {
1013
+
1014
+ }
1015
+ }
1016
+
1017
+ -(void)validateIntegration:(CDVInvokedUrlCommand *)command {
1018
+ @try {
1019
+ [self.commandDelegate runInBackground:^{
1020
+ @try {
1021
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
1022
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1023
+ } @catch(NSException *e) {
1024
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
1025
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
1026
+ }
1027
+ }];
1028
+ } @catch (NSException *exception) {
1029
+
1030
+ } @finally {
1031
+
1032
+ }
1033
+ }
1034
+
1035
+ - (void)sendNotification:(NSDictionary *)userInfo {
1036
+ @try {
1037
+ NSLog(@"Appice send-notifcallback a1 %@",notificationCallbackId);
1038
+ if (self.notificationCallbackId != nil) {
1039
+ NSLog(@"Appice send-notifcallback a2");
1040
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userInfo];
1041
+ [pluginResult setKeepCallbackAsBool:YES];
1042
+ NSLog(@"Appice send-notifcallback a3");
1043
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.notificationCallbackId];
1044
+ NSLog(@"Appice send-notifcallback a4");
1045
+ } else {
1046
+ NSLog(@"Appice send-notifcallback a5");
1047
+ if (!self.notificationStack) {
1048
+ NSLog(@"Appice send-notifcallback a6");
1049
+ self.notificationStack = [[NSMutableArray alloc] init];
1050
+ }
1051
+ NSLog(@"Appice send-notifcallback a7");
1052
+ // stack notifications until a callback has been registered
1053
+ [self.notificationStack addObject:userInfo];
1054
+
1055
+ if ([self.notificationStack count] >= kNotificationStackSize) {
1056
+ [self.notificationStack removeLastObject];
1057
+ }
1058
+ }
1059
+ } @catch (NSException *exception) {
1060
+
1061
+ } @finally {
1062
+
1063
+ }
1064
+ }
1065
+
1066
+ @end
1067
+
1068
+