cordova-plugin-appice 2.2.1 → 2.2.2
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/example/www/index.html +89 -52
- package/example/www/js/AppInboxMessage.js +58 -0
- package/example/www/js/index.js +580 -99
- package/package.json +1 -1
- package/plugin.xml +6 -5
- package/src/android/AppICEPlugin.java +567 -54
- package/src/ios/AppICEPlugin.h +17 -1
- package/src/ios/AppICEPlugin.m +384 -12
- package/www/AppICE.js +86 -3
package/src/ios/AppICEPlugin.h
CHANGED
|
@@ -91,6 +91,22 @@ static NSString* const AIHandleActionNotification = @"AIHandleActionNotification
|
|
|
91
91
|
|
|
92
92
|
//new empty function
|
|
93
93
|
-(void)isDeviceReady:(CDVInvokedUrlCommand *)command;
|
|
94
|
-
|
|
94
|
+
- (void)getMessageCountForUserIds:(CDVInvokedUrlCommand*)command;
|
|
95
|
+
- (void)getInboxMessagesForUserIds:(CDVInvokedUrlCommand*)command;
|
|
96
|
+
- (void)getInboxMessageForIdWithUserId:(CDVInvokedUrlCommand*)command;
|
|
97
|
+
- (void)updateInboxMessageForUserId:(CDVInvokedUrlCommand*)command;
|
|
98
|
+
- (void)synchronizeInbox:(CDVInvokedUrlCommand*)command;
|
|
99
|
+
- (void)synchronizeData:(CDVInvokedUrlCommand*)command;
|
|
100
|
+
- (void)getMediaUrl:(CDVInvokedUrlCommand*)command;
|
|
101
|
+
- (void)getMediaType:(CDVInvokedUrlCommand*)command;
|
|
102
|
+
- (void)getMediaThumbnail:(CDVInvokedUrlCommand*)command;
|
|
103
|
+
- (void)getMessageCount:(CDVInvokedUrlCommand*)command;
|
|
104
|
+
- (void)getInboxMessages:(CDVInvokedUrlCommand*)command;
|
|
105
|
+
- (void)updateInboxMessage:(CDVInvokedUrlCommand*)command;
|
|
106
|
+
- (void)getMediaData:(CDVInvokedUrlCommand*)command;
|
|
107
|
+
- (void)scheduleCampaign:(CDVInvokedUrlCommand*)command;
|
|
108
|
+
- (void)getUserId:(CDVInvokedUrlCommand*)command;
|
|
109
|
+
- (void)getUserForIds:(CDVInvokedUrlCommand*)command;
|
|
110
|
+
- (void)getInboxMessageForId:(CDVInvokedUrlCommand*)command;
|
|
95
111
|
@end
|
|
96
112
|
|
package/src/ios/AppICEPlugin.m
CHANGED
|
@@ -50,7 +50,11 @@ static NSDictionary *pendingDeeplink = nil;
|
|
|
50
50
|
|
|
51
51
|
+(void)onDidFinishLaunchingNotification:(NSNotification *)notification {
|
|
52
52
|
// Init appice
|
|
53
|
-
|
|
53
|
+
NSDictionary *userInfo = notification.userInfo;
|
|
54
|
+
AppICEPlugin *appice = [[AppICEPlugin alloc] init];
|
|
55
|
+
[appice storePendingDeeplink:userInfo];
|
|
56
|
+
NSLog(@"Deeplink Push: onDidFinishLaunchingNotification storePendingDeeplink: %@", userInfo);
|
|
57
|
+
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
-(void)handleToken:(NSData *)deviceToken {
|
|
@@ -1123,15 +1127,27 @@ static NSDictionary *pendingDeeplink = nil;
|
|
|
1123
1127
|
NSLog(@"Deeplink Push STATE 4: processPendingDeeplink called, isAppInitialized: %d, pendingDeeplink: %@", isAppInitialized, pendingDeeplink);
|
|
1124
1128
|
if (isAppInitialized && pendingDeeplink) {
|
|
1125
1129
|
NSLog(@"Deeplink Push : STATE 4 handled stored data");
|
|
1126
|
-
|
|
1127
|
-
|
|
1130
|
+
|
|
1131
|
+
/* UIApplicationLaunchOptionsRemoteNotificationKey when payload is stored on launch of the application the key is appending on it automatically so checking condition for push payload to fetch message*/
|
|
1132
|
+
|
|
1133
|
+
NSDictionary *pendingPayload;
|
|
1134
|
+
if (pendingDeeplink[@"UIApplicationLaunchOptionsRemoteNotificationKey"]) {
|
|
1135
|
+
// Extract only the relevant part of the payload
|
|
1136
|
+
pendingPayload = pendingDeeplink[@"UIApplicationLaunchOptionsRemoteNotificationKey"];
|
|
1137
|
+
}
|
|
1138
|
+
// If UIApplicationLaunchOptionsRemoteNotificationKey is not present, fallback to pendingDeeplink
|
|
1139
|
+
if (!pendingPayload) {
|
|
1140
|
+
pendingPayload = pendingDeeplink;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
[[appICE sharedInstance] handleClickOnPush:pendingPayload OpenDeepLink:YES];
|
|
1144
|
+
[self eventClickedPayload:pendingPayload];
|
|
1128
1145
|
|
|
1129
1146
|
pendingDeeplink = nil;
|
|
1130
1147
|
}
|
|
1131
1148
|
} @catch (NSException *exception) {
|
|
1132
1149
|
NSLog(@"Deeplink Push : processPendingDeeplink exception %@", exception);
|
|
1133
1150
|
} @finally {
|
|
1134
|
-
pendingDeeplink = nil;
|
|
1135
1151
|
NSLog(@"Deeplink Push : finally processPendingDeeplink pendingDeeplink set to nil");
|
|
1136
1152
|
}
|
|
1137
1153
|
}
|
|
@@ -1152,19 +1168,375 @@ static NSDictionary *pendingDeeplink = nil;
|
|
|
1152
1168
|
}
|
|
1153
1169
|
|
|
1154
1170
|
- (void)eventClickedPayload:(NSDictionary *)userInfo {
|
|
1155
|
-
|
|
1156
1171
|
NSDictionary *pushPayload = [userInfo valueForKeyPath:@"data.message"];
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1172
|
+
if(pushPayload)
|
|
1173
|
+
{
|
|
1174
|
+
NSError *error = nil;
|
|
1175
|
+
NSData *payloadData = [NSJSONSerialization dataWithJSONObject:pushPayload
|
|
1176
|
+
options:kNilOptions
|
|
1177
|
+
error:&error];
|
|
1178
|
+
if (error) {
|
|
1179
|
+
NSLog(@"Deeplink Push: Error serializing payload: %@", error.localizedDescription);
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
NSString *payloadString = [[NSString alloc] initWithData:payloadData encoding:NSUTF8StringEncoding];
|
|
1184
|
+
if (!payloadString) {
|
|
1185
|
+
NSLog(@"Deeplink Push: Failed to convert payload data to string");
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
NSLog(@"Deeplink Push :payloadString string: %@", payloadString);
|
|
1189
|
+
|
|
1190
|
+
NSString *js = [NSString stringWithFormat:@"pushNotificationClicked({'payload':'%@'});",payloadString];
|
|
1191
|
+
[self.commandDelegate evalJs:js];
|
|
1192
|
+
}
|
|
1193
|
+
else{
|
|
1194
|
+
NSLog(@"Deeplink Push :eventClickedPayload is empty");
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// MARK: - App inbox api's
|
|
1199
|
+
|
|
1200
|
+
- (void)synchronizeInbox:(CDVInvokedUrlCommand*)command {
|
|
1201
|
+
@try {
|
|
1202
|
+
[self.commandDelegate runInBackground:^{
|
|
1203
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1204
|
+
NSNumber* timeout = [eventObj valueForKey:@"timeout"];
|
|
1205
|
+
// Ensure timeout is valid before proceeding
|
|
1206
|
+
if (![timeout isKindOfClass:[NSNumber class]]) {
|
|
1207
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Timeout"];
|
|
1208
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
// Call SDK method with the timeout
|
|
1212
|
+
[[appICE sharedInstance] synchronizeInbox:^(BOOL success) {
|
|
1213
|
+
CDVPluginResult *result = nil;
|
|
1214
|
+
if (success) {
|
|
1215
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"synchronizeInbox successful"];
|
|
1216
|
+
} else {
|
|
1217
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"synchronizeInbox failed"];
|
|
1218
|
+
}
|
|
1219
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1220
|
+
} timeoutinSec:[timeout intValue]];
|
|
1221
|
+
}];
|
|
1222
|
+
} @catch (NSException *exception) {
|
|
1223
|
+
NSLog(@"INBOX : synchronizeInbox exception %@", exception);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/*=====================
|
|
1228
|
+
APPINBOX with UserId
|
|
1229
|
+
===================== */
|
|
1230
|
+
|
|
1231
|
+
- (void)getMessageCountForUserIds:(CDVInvokedUrlCommand*)command {
|
|
1232
|
+
@try {
|
|
1233
|
+
[self.commandDelegate runInBackground:^{
|
|
1234
|
+
NSObject *eventObjMsgCountStatus = [command argumentAtIndex:0];
|
|
1235
|
+
NSNumber *status = [eventObjMsgCountStatus valueForKey:@"type"];
|
|
1236
|
+
NSArray *userIdArray = [eventObjMsgCountStatus valueForKey:@"userId"];
|
|
1237
|
+
// Ensure status is valid before proceeding
|
|
1238
|
+
if (![status isKindOfClass:[NSNumber class]]) {
|
|
1239
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1240
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
// Call SDK method with the status
|
|
1244
|
+
int messageCount = [[appICE sharedInstance] getMessageCount:[status intValue] userId:userIdArray];
|
|
1245
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1246
|
+
messageAsInt:messageCount];
|
|
1247
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1248
|
+
}];
|
|
1249
|
+
} @catch (NSException *exception) {
|
|
1250
|
+
NSLog(@"INBOX : getMessageCountForUserIds exception %@", exception);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
- (void)getInboxMessagesForUserIds:(CDVInvokedUrlCommand*)command {
|
|
1255
|
+
@try {
|
|
1256
|
+
[self.commandDelegate runInBackground:^{
|
|
1257
|
+
NSObject *eventObjMsgCountStatus = [command argumentAtIndex:0];
|
|
1258
|
+
NSNumber *status = [eventObjMsgCountStatus valueForKey:@"type"];
|
|
1259
|
+
NSArray *userIdArray = [eventObjMsgCountStatus valueForKey:@"userId"];
|
|
1260
|
+
// Ensure status is valid before proceeding
|
|
1261
|
+
if (![status isKindOfClass:[NSNumber class]]) {
|
|
1262
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1263
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
// Call SDK method with the status
|
|
1267
|
+
NSMutableArray *inboxMessages = [[appICE sharedInstance] getInboxMessages:[status intValue] userId:userIdArray];
|
|
1268
|
+
NSArray *messageDictArray = [self arrayFromInboxMessages:inboxMessages];
|
|
1269
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1270
|
+
messageAsArray:messageDictArray];
|
|
1271
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1272
|
+
}];
|
|
1273
|
+
} @catch (NSException *exception) {
|
|
1274
|
+
NSLog(@"INBOX : getInboxMessagesForUserIds exception %@", exception);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
- (void)getInboxMessageForIdWithUserId:(CDVInvokedUrlCommand*)command {
|
|
1279
|
+
@try {
|
|
1280
|
+
[self.commandDelegate runInBackground:^{
|
|
1281
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1282
|
+
NSString *messageId = [eventObj valueForKey:@"messageId"];
|
|
1283
|
+
NSString *userId = [eventObj valueForKey:@"userId"];
|
|
1284
|
+
// Ensure both ids are there before proceeding
|
|
1285
|
+
if (!messageId || [messageId isEqualToString:@""] || !userId || [userId isEqualToString:@""]) {
|
|
1286
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1287
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
// Call SDK method with messageId, userId
|
|
1291
|
+
AppICEInboxMessage *inboxMessagesForID = [[appICE sharedInstance] getInboxMessageForId:messageId usrId:userId];
|
|
1292
|
+
NSDictionary *messageDict = [inboxMessagesForID toDictionary];
|
|
1293
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1294
|
+
messageAsDictionary:messageDict];
|
|
1295
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1296
|
+
}];
|
|
1297
|
+
} @catch (NSException *exception) {
|
|
1298
|
+
NSLog(@"INBOX : getInboxMessageForIdWithUserId exception %@", exception);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
- (void)updateInboxMessageForUserId:(CDVInvokedUrlCommand*)command {
|
|
1303
|
+
@try {
|
|
1304
|
+
[self.commandDelegate runInBackground:^{
|
|
1305
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1306
|
+
NSNumber *status = [eventObj valueForKey:@"type"];
|
|
1307
|
+
NSString *messageId = [eventObj valueForKey:@"messageId"];
|
|
1308
|
+
NSString *userId = [eventObj valueForKey:@"userId"];
|
|
1309
|
+
// Ensure both ids are there before proceeding
|
|
1310
|
+
if (!messageId || [messageId isEqualToString:@""] || !userId || [userId isEqualToString:@""]) {
|
|
1311
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1312
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
// Call SDK method with the status, messageId, userId
|
|
1316
|
+
BOOL inboxUpdated = [[appICE sharedInstance] updateInboxMessage:[status intValue] messageId:messageId userid:userId];
|
|
1317
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1318
|
+
messageAsBool:inboxUpdated];
|
|
1319
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1320
|
+
}];
|
|
1321
|
+
} @catch (NSException *exception) {
|
|
1322
|
+
NSLog(@"INBOX : updateInboxMessageForUserId exception %@", exception);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
- (void)getMediaData:(CDVInvokedUrlCommand*)command {
|
|
1327
|
+
@try {
|
|
1328
|
+
[self.commandDelegate runInBackground:^{
|
|
1329
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1330
|
+
NSDictionary *dataDict = [eventObj valueForKey:@"inboxMessages"];
|
|
1331
|
+
NSString *mediaKey = [eventObj valueForKey:@"mediaKey"];
|
|
1332
|
+
// Initialize AppICEInboxMessage from dictionary
|
|
1333
|
+
AppICEInboxMessage *inboxMessage = [AppICEInboxMessage instanceFromDictionary:dataDict];
|
|
1334
|
+
// Ensure inboxMessage is correctly initialized
|
|
1335
|
+
if (![inboxMessage isKindOfClass:[AppICEInboxMessage class]]) {
|
|
1336
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Inbox Message"];
|
|
1337
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
// Fetch the correct media property using the corresponding methods
|
|
1341
|
+
NSDictionary *mediaData = [inboxMessage mediaData:mediaKey];
|
|
1342
|
+
|
|
1343
|
+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:mediaData];
|
|
1344
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
1345
|
+
}];
|
|
1346
|
+
} @catch (NSException *exception) {
|
|
1347
|
+
NSLog(@"INBOX : getMediaData exception %@", exception);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
- (void)fetchMediaProperty:(CDVInvokedUrlCommand*)command propertyKey:(NSString *)propertyKey {
|
|
1352
|
+
@try {
|
|
1353
|
+
[self.commandDelegate runInBackground:^{
|
|
1354
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1355
|
+
NSDictionary *dataDict = [eventObj valueForKey:@"inboxMessages"];
|
|
1356
|
+
NSDictionary *mediaData = [eventObj valueForKey:@"mediaData"];
|
|
1357
|
+
|
|
1358
|
+
// Initialize AppICEInboxMessage from dictionary
|
|
1359
|
+
AppICEInboxMessage *inboxMessage = [AppICEInboxMessage instanceFromDictionary:dataDict];
|
|
1360
|
+
|
|
1361
|
+
// Ensure inboxMessage is correctly initialized
|
|
1362
|
+
if (![inboxMessage isKindOfClass:[AppICEInboxMessage class]]) {
|
|
1363
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Inbox Message"];
|
|
1364
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// Fetch the media property dynamically
|
|
1369
|
+
NSString *mediaPropertyResult = nil;
|
|
1370
|
+
if ([propertyKey isEqualToString:@"mediaUrl"]) {
|
|
1371
|
+
mediaPropertyResult = [inboxMessage mediaUrl:mediaData];
|
|
1372
|
+
} else if ([propertyKey isEqualToString:@"mediaType"]) {
|
|
1373
|
+
mediaPropertyResult = [inboxMessage mediaType:mediaData];
|
|
1374
|
+
} else if ([propertyKey isEqualToString:@"mediaThumbnail"]) {
|
|
1375
|
+
mediaPropertyResult = [inboxMessage mediaThumbnail:mediaData];
|
|
1376
|
+
} else {
|
|
1377
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Property Key"];
|
|
1378
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// Return the result
|
|
1383
|
+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:mediaPropertyResult];
|
|
1384
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
1385
|
+
}];
|
|
1386
|
+
} @catch (NSException *exception) {
|
|
1387
|
+
NSLog(@"INBOX : fetchMediaProperty exception %@", exception);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
- (void)getMediaUrl:(CDVInvokedUrlCommand*)command {
|
|
1392
|
+
[self fetchMediaProperty:command propertyKey:@"mediaUrl"];
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
- (void)getMediaType:(CDVInvokedUrlCommand*)command {
|
|
1396
|
+
[self fetchMediaProperty:command propertyKey:@"mediaType"];
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
- (void)getMediaThumbnail:(CDVInvokedUrlCommand*)command {
|
|
1400
|
+
[self fetchMediaProperty:command propertyKey:@"mediaThumbnail"];
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/*======================
|
|
1404
|
+
AppINBOX without UserID
|
|
1405
|
+
======================*/
|
|
1406
|
+
|
|
1407
|
+
- (void)getMessageCount:(CDVInvokedUrlCommand*)command {
|
|
1408
|
+
@try {
|
|
1409
|
+
[self.commandDelegate runInBackground:^{
|
|
1410
|
+
NSObject *eventObjMsgCountStatus = [command argumentAtIndex:0];
|
|
1411
|
+
NSNumber *status = [eventObjMsgCountStatus valueForKey:@"type"];
|
|
1412
|
+
// Ensure status is valid before proceeding
|
|
1413
|
+
if (![status isKindOfClass:[NSNumber class]]) {
|
|
1414
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1415
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
// Call SDK method with the status
|
|
1419
|
+
int messageCount = [[appICE sharedInstance] getMessageCount:[status intValue]];
|
|
1420
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1421
|
+
messageAsInt:messageCount];
|
|
1422
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1423
|
+
}];
|
|
1424
|
+
} @catch (NSException *exception) {
|
|
1425
|
+
NSLog(@"INBOX : getMessageCount exception %@", exception);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
- (void)getInboxMessages:(CDVInvokedUrlCommand*)command {
|
|
1430
|
+
@try {
|
|
1431
|
+
[self.commandDelegate runInBackground:^{
|
|
1432
|
+
NSObject *eventObjMsgCountStatus = [command argumentAtIndex:0];
|
|
1433
|
+
NSNumber *status = [eventObjMsgCountStatus valueForKey:@"type"];
|
|
1434
|
+
// Ensure status is valid before proceeding
|
|
1435
|
+
if (![status isKindOfClass:[NSNumber class]]) {
|
|
1436
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid status"];
|
|
1437
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
// Call SDK method with the status /AppICEInboxMessage
|
|
1441
|
+
NSMutableArray *inboxMessages = [[appICE sharedInstance] getInboxMessages:[status intValue]];
|
|
1442
|
+
NSArray *messageDictArray = [self arrayFromInboxMessages:inboxMessages];
|
|
1443
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1444
|
+
messageAsArray:messageDictArray];
|
|
1445
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1446
|
+
}];
|
|
1447
|
+
} @catch (NSException *exception) {
|
|
1448
|
+
NSLog(@"INBOX : getInboxMessages exception %@", exception);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
- (void)updateInboxMessage:(CDVInvokedUrlCommand*)command {
|
|
1453
|
+
@try {
|
|
1454
|
+
[self.commandDelegate runInBackground:^{
|
|
1455
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1456
|
+
NSNumber *status = [eventObj valueForKey:@"type"];
|
|
1457
|
+
NSString *messageId = [eventObj valueForKey:@"messageId"];
|
|
1458
|
+
// Ensure both ids are there before proceeding
|
|
1459
|
+
if (!messageId || [messageId isEqualToString:@""] || ![status isKindOfClass:[NSNumber class]]) {
|
|
1460
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid messageId or status"];
|
|
1461
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
// Call SDK method with the status
|
|
1465
|
+
BOOL inboxUpdated = [[appICE sharedInstance] updateInboxMessage:[status intValue] :messageId];
|
|
1466
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1467
|
+
messageAsBool:inboxUpdated];
|
|
1468
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1469
|
+
}];
|
|
1470
|
+
} @catch (NSException *exception) {
|
|
1471
|
+
NSLog(@"INBOX : updateInboxMessage exception %@", exception);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
- (void)getInboxMessageForId:(CDVInvokedUrlCommand*)command {
|
|
1476
|
+
@try {
|
|
1477
|
+
[self.commandDelegate runInBackground:^{
|
|
1478
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1479
|
+
NSString *messageId = [eventObj valueForKey:@"messageId"];
|
|
1480
|
+
// Ensure messageId are there and not empty before proceeding
|
|
1481
|
+
if (!messageId || [messageId isEqualToString:@""]) {
|
|
1482
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid messageId"];
|
|
1483
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1486
|
+
// Call SDK method with the messageId
|
|
1487
|
+
AppICEInboxMessage *inboxMessagesForID = [[appICE sharedInstance] getInboxMessageForId:messageId];
|
|
1488
|
+
NSDictionary *messageDict = [inboxMessagesForID toDictionary];
|
|
1489
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
1490
|
+
messageAsDictionary:messageDict];
|
|
1491
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1492
|
+
}];
|
|
1493
|
+
} @catch (NSException *exception) {
|
|
1494
|
+
NSLog(@"INBOX : getInboxMessageForId exception %@", exception);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
- (void)scheduleCampaign:(CDVInvokedUrlCommand*)command {
|
|
1499
|
+
// TODO: @(chhavi krishan) Implement campaign scheduling
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
- (void)synchronizeData:(CDVInvokedUrlCommand*)command {
|
|
1162
1503
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1504
|
+
[self.commandDelegate runInBackground:^{
|
|
1505
|
+
NSObject *eventObj = [command argumentAtIndex:0];
|
|
1506
|
+
NSNumber* timeout = [eventObj valueForKey:@"timeout"];
|
|
1507
|
+
// Ensure timeout is valid before proceeding
|
|
1508
|
+
if (![timeout isKindOfClass:[NSNumber class]]) {
|
|
1509
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid Timeout"];
|
|
1510
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
// Call SDK method with the timeout
|
|
1514
|
+
[[appICE sharedInstance] synchronizeData:^(BOOL success) {
|
|
1515
|
+
CDVPluginResult *result = nil;
|
|
1516
|
+
if (success) {
|
|
1517
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"synchronizeData successful"];
|
|
1518
|
+
} else {
|
|
1519
|
+
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"synchronizeData failed"];
|
|
1520
|
+
}
|
|
1521
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
1522
|
+
} timeoutinSec:[timeout intValue]];
|
|
1523
|
+
}];
|
|
1165
1524
|
}
|
|
1166
1525
|
|
|
1526
|
+
- (void)getUserId:(CDVInvokedUrlCommand*)command { }
|
|
1527
|
+
- (void)getUserForIds:(CDVInvokedUrlCommand*)command { }
|
|
1167
1528
|
|
|
1529
|
+
//-------------- End of app inbox api's----------------
|
|
1530
|
+
|
|
1531
|
+
//Convert AppICEInboxMessages to array
|
|
1532
|
+
- (NSArray *)arrayFromInboxMessages:(NSArray<AppICEInboxMessage *> *)messages {
|
|
1533
|
+
NSMutableArray *messageDictArray = [NSMutableArray array];
|
|
1534
|
+
for (AppICEInboxMessage *message in messages) {
|
|
1535
|
+
NSDictionary *messageDict = [message toDictionary];
|
|
1536
|
+
[messageDictArray addObject:messageDict];
|
|
1537
|
+
}
|
|
1538
|
+
return [messageDictArray copy];
|
|
1539
|
+
}
|
|
1168
1540
|
@end
|
|
1169
1541
|
|
|
1170
1542
|
|
package/www/AppICE.js
CHANGED
|
@@ -159,6 +159,10 @@ cordova.define("cordova-plugin-appice.AppICE", function (require, exports, modul
|
|
|
159
159
|
AppICE.prototype.setUserId = function (userID, success, error) {
|
|
160
160
|
cordova.exec(success, error, "AppICEPlugin", "setUserId", [{ "userID": userID }]);
|
|
161
161
|
};
|
|
162
|
+
|
|
163
|
+
AppICE.prototype.getUserId = function (success, error) {
|
|
164
|
+
cordova.exec(success, error, "AppICEPlugin", "getUserId", []);
|
|
165
|
+
};
|
|
162
166
|
|
|
163
167
|
//=============================
|
|
164
168
|
// CHILD KEY SETTING APIS
|
|
@@ -261,8 +265,8 @@ cordova.define("cordova-plugin-appice.AppICE", function (require, exports, modul
|
|
|
261
265
|
if (parsedPayload.hasOwnProperty('cdata') && parsedPayload.cdata.hasOwnProperty(key)) {
|
|
262
266
|
success(parsedPayload.cdata[key]);
|
|
263
267
|
}
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
|
|
269
|
+
//error('something is wrong please try again with valid data');
|
|
266
270
|
} catch (errMessage) {
|
|
267
271
|
error(errMessage)
|
|
268
272
|
}
|
|
@@ -343,7 +347,86 @@ cordova.define("cordova-plugin-appice.AppICE", function (require, exports, modul
|
|
|
343
347
|
cordova.exec(success, error, "AppICEPlugin", "trackScreens", [{ "old": e.oldURL, "new": e.newURL, "loc": location.hash, "h": document.documentElement.clientHeight, "w": document.documentElement.clientWidth, "arr": inputArr }]);
|
|
344
348
|
};
|
|
345
349
|
|
|
346
|
-
|
|
350
|
+
/*===============================
|
|
351
|
+
Inbox APIS
|
|
352
|
+
===============================*/
|
|
353
|
+
|
|
354
|
+
AppICE.prototype.synchronizeInbox = function (timeout, success, error) {
|
|
355
|
+
cordova.exec(success, error, "AppICEPlugin", "synchronizeInbox", [{"timeout": timeout}]);
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/**** with UserId****/
|
|
359
|
+
|
|
360
|
+
AppICE.prototype.getInboxMessagesForUserIds = function (type, userId, success, error) {
|
|
361
|
+
cordova.exec(success, error, "AppICEPlugin", "getInboxMessagesForUserIds", [{"type": type, "userId": userId}]);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
AppICE.prototype.getMessageCountForUserIds = function (type, userId, success, error) {
|
|
365
|
+
cordova.exec(success, error, "AppICEPlugin", "getMessageCountForUserIds", [{"type": type, "userId": userId}]);
|
|
366
|
+
};
|
|
347
367
|
|
|
368
|
+
AppICE.prototype.getInboxMessageForIdWithUserId = function (messageId, userId, success, error) {
|
|
369
|
+
cordova.exec(success, error, "AppICEPlugin", "getInboxMessageForIdWithUserId", [{"messageId": messageId, "userId": userId}]);
|
|
370
|
+
};
|
|
348
371
|
|
|
372
|
+
AppICE.prototype.updateInboxMessageForUserId = function (messageId, type, userId,success, error) {
|
|
373
|
+
cordova.exec(success, error, "AppICEPlugin", "updateInboxMessageForUserId", [{"messageId": messageId, "type":type,"userId": userId}]);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/****** without UserId *******/
|
|
377
|
+
|
|
378
|
+
AppICE.prototype.getInboxMessages = function (type, success, error) {
|
|
379
|
+
cordova.exec(success, error, "AppICEPlugin", "getInboxMessages", [{"type": type}]);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
AppICE.prototype.getMessageCount = function (type, success, error) {
|
|
383
|
+
cordova.exec(success, error, "AppICEPlugin", "getMessageCount", [{"type": type}]);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
AppICE.prototype.getInboxMessageForId = function (messageId, success, error) {
|
|
387
|
+
cordova.exec(success, error, "AppICEPlugin", "getInboxMessageForId", [{"messageId": messageId}]);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
AppICE.prototype.updateInboxMessage = function (messageId, type, success, error) {
|
|
391
|
+
cordova.exec(success, error, "AppICEPlugin", "updateInboxMessage", [{"messageId": messageId, "type":type}]);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/*********for RichPush******/
|
|
395
|
+
|
|
396
|
+
AppICE.prototype.getMediaData = function (inboxMessages, mediaKey, success, error) {
|
|
397
|
+
cordova.exec(success, error, "AppICEPlugin", "getMediaData", [{"inboxMessages": inboxMessages, "mediaKey": mediaKey}]);
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
AppICE.prototype.getMediaUrl = function (inboxMessages, mediaData, success, error) {
|
|
401
|
+
cordova.exec(success, error, "AppICEPlugin", "getMediaUrl", [{"inboxMessages": inboxMessages, "mediaData": mediaData}]);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
AppICE.prototype.getMediaType = function (inboxMessages, mediaData, success, error) {
|
|
405
|
+
cordova.exec(success, error, "AppICEPlugin", "getMediaType", [{"inboxMessages": inboxMessages, "mediaData": mediaData}]);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
AppICE.prototype.getMediaThumbnail = function (inboxMessages, mediaData, success, error) {
|
|
409
|
+
cordova.exec(success, error, "AppICEPlugin", "getMediaThumbnail", [{ "inboxMessages": inboxMessages, "mediaData": mediaData}]);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/*====================
|
|
413
|
+
Push Action
|
|
414
|
+
====================== */
|
|
415
|
+
AppICE.prototype.scheduleCampaign = function (cmpid, dur, userId, success, error) {
|
|
416
|
+
cordova.exec(success, error, "AppICEPlugin", "scheduleCampaign", [{"cmpid": cmpid, "dur":dur,"userId": userId}]);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
/*===============================
|
|
420
|
+
Quick Action APIS
|
|
421
|
+
=============================*/
|
|
422
|
+
|
|
423
|
+
AppICE.prototype.getUserForIds = function (userIds, success, error) {
|
|
424
|
+
cordova.exec(success, error, "AppICEPlugin", "getUserForIds", [{"userIds": userIds}]);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
AppICE.prototype.synchronizeData = function (timeout, success, error) {
|
|
428
|
+
cordova.exec(success, error, "AppICEPlugin", "synchronizeData", [{"timeout": timeout}]);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
module.exports = new AppICE();
|
|
349
432
|
});
|