cordova-plugin-appice 2.0.8 → 2.0.10

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.
Files changed (31) hide show
  1. package/README.md +120 -122
  2. package/package.json +45 -27
  3. package/plugin.xml +168 -103
  4. package/scripts/BeforeAndroidBuilt.js +160 -126
  5. package/scripts/BeforeIosBuilt.js +38 -38
  6. package/scripts/androidAfterPluginAdd.js +159 -159
  7. package/scripts/androidAfterPluginRm.js +195 -195
  8. package/scripts/iOSAfterPluginAdd.js +98 -98
  9. package/scripts/iOSAfterPluginRm.js +73 -74
  10. package/src/android/AppICEMFPPush.java +177 -0
  11. package/{libcordova/src/main/java/com/appice/cordova → src/android}/AppICEPlugin.java +405 -489
  12. package/{libcordova/src/main/java/com/appice/cordova → src/android}/CampaignCampsReceiver.java +8 -9
  13. package/{libcordova/src/main/java/com/appice/cordova → src/android}/NotificationEventService.java +16 -7
  14. package/src/build.gradle +16 -14
  15. package/src/firebase/modified/android/FirebasePluginMessagingService.java +356 -356
  16. package/src/firebase/modified/ios/AppDelegate+FirebasePlugin.m +529 -529
  17. package/src/firebase/original/android/FirebasePluginMessagingService.java +348 -348
  18. package/src/firebase/original/ios/AppDelegate+FirebasePlugin.m +519 -519
  19. package/src/ios/AppDelegate+AppICEPlugin.h +8 -8
  20. package/src/ios/AppDelegate+AppICEPlugin.m +278 -191
  21. package/src/ios/AppICEPlugin.h +93 -90
  22. package/src/ios/AppICEPlugin.m +1161 -1062
  23. package/www/AppICE.js +289 -284
  24. package/libcordova/android-release-aar.gradle +0 -63
  25. package/libcordova/build.gradle +0 -50
  26. package/libcordova/cordova.jar +0 -0
  27. package/libcordova/proguard-rules.pro +0 -21
  28. package/libcordova/src/main/AndroidManifest.xml +0 -24
  29. package/libcordova/src/main/res/values/strings.xml +0 -3
  30. package/src/firebase/modified/modified.iml +0 -11
  31. package/src/firebase/original/original.iml +0 -11
@@ -1,75 +1,74 @@
1
- #!/usr/bin/env node
2
-
3
- module.exports = function(context) {
4
-
5
- var fs = require('fs');
6
- var path = require('path');
7
- var shell = require('shelljs');
8
-
9
- const cordovaCommon = context.requireCordovaModule('cordova-common');
10
- const appConfig = new cordovaCommon.ConfigParser('config.xml');
11
- var appName = appConfig.name();
12
-
13
- var platformRoot = path.join(context.opts.projectRoot, 'platforms/ios');
14
- var pluginsFirebaseRoot = path.join(context.opts.projectRoot, 'plugins/cordova-plugin-firebasex');
15
- var pluginsAppiceRoot = path.join(context.opts.projectRoot, 'plugins/cordova-plugin-appice');
16
- var APPICE_FIREBASE_UPDATE = appConfig.getPlatformPreference("APPICE_FIREBASE_UPDATE", "ios");
17
- var APPICE_APPLICATIONCLASS_INCLUDE= appConfig.getPlatformPreference("APPICE_APPLICATIONCLASS_INCLUDE", "ios");
18
- var SSL_PINNING=appConfig.getPlatformPreference("SSL_PINNING", "ios");
19
-
20
- var firebaseFile1 = path.join(platformRoot, '/'+appName+'/Plugins/cordova-plugin-firebasex/AppDelegate+FirebasePlugin.m');
21
- if (fs.existsSync(firebaseFile1)) {
22
- try {
23
- shell.rm('-Rf', firebaseFile1);
24
- } catch(err) {
25
- }
26
- }
27
-
28
- var modifiedFile1 = path.join(pluginsAppiceRoot, '/src/firebase/original/ios/AppDelegate+FirebasePlugin.m');
29
- try {
30
- shell.cp('-f', modifiedFile1, firebaseFile1);
31
- } catch(err) {
32
- }
33
-
34
- var firebaseFile2 = path.join(pluginsFirebaseRoot, '/src/ios/AppDelegate+FirebasePlugin.m');
35
- if (fs.existsSync(firebaseFile2)) {
36
- try {
37
- shell.rm('-Rf', firebaseFile2);
38
- } catch(err) {
39
- }
40
- }
41
-
42
- try {
43
- shell.cp('-f', modifiedFile1, firebaseFile2);
44
- } catch(err) {
45
- }
46
-
47
- if(SSL_PINNING === "true"){
48
- console.log("appName : "+appName);
49
- var get_info_plist=path.join(platformRoot,appName+ '/'+appName+'-Info.plist');
50
- if(fs.existsSync(get_info_plist)){
51
- console.log("ssl");
52
- try{
53
- fs.readFile(get_info_plist, 'utf8', function (err,data) {
54
- if (err) {
55
- throw new Error('Unable to find Plist: ' + err);
56
- }
57
- ///for removing SSL pinning
58
- var SSL_PINNING_key = '<key>APPICE_SSL_PINNING</key>\n<true/>';
59
- if (data.indexOf(SSL_PINNING_key) == -1) {
60
- var result = data.replace('APPICE_SSL_PINNING','');
61
- fs.writeFile(get_info_plist, result, 'utf8', function (err) {
62
- if (err) {
63
- throw new Error('Unable to write into Plist: ' + err);
64
- }
65
- });
66
-
67
- }
68
- });
69
- }
70
- catch(err) {
71
- }
72
- }
73
-
74
- }
1
+ #!/usr/bin/env node
2
+
3
+ module.exports = function (context) {
4
+
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var shell = require('shelljs');
8
+
9
+ const cordovaCommon = context.requireCordovaModule('cordova-common');
10
+ const appConfig = new cordovaCommon.ConfigParser('config.xml');
11
+ var appName = appConfig.name();
12
+
13
+ var platformRoot = path.join(context.opts.projectRoot, 'platforms/ios');
14
+ var pluginsFirebaseRoot = path.join(context.opts.projectRoot, 'plugins/cordova-plugin-firebasex');
15
+ var pluginsAppiceRoot = path.join(context.opts.projectRoot, 'plugins/cordova-plugin-appice');
16
+ var APPICE_FIREBASE_UPDATE = appConfig.getPlatformPreference("APPICE_FIREBASE_UPDATE", "ios");
17
+ var APPICE_APPLICATIONCLASS_INCLUDE = appConfig.getPlatformPreference("APPICE_APPLICATIONCLASS_INCLUDE", "ios");
18
+ var SSL_PINNING = appConfig.getPlatformPreference("SSL_PINNING", "ios");
19
+
20
+ var firebaseFile1 = path.join(platformRoot, '/' + appName + '/Plugins/cordova-plugin-firebasex/AppDelegate+FirebasePlugin.m');
21
+ if (fs.existsSync(firebaseFile1)) {
22
+ try {
23
+ shell.rm('-Rf', firebaseFile1);
24
+ } catch (err) {
25
+ }
26
+ }
27
+
28
+ var modifiedFile1 = path.join(pluginsAppiceRoot, '/src/firebase/original/ios/AppDelegate+FirebasePlugin.m');
29
+ try {
30
+ shell.cp('-f', modifiedFile1, firebaseFile1);
31
+ } catch (err) {
32
+ }
33
+
34
+ var firebaseFile2 = path.join(pluginsFirebaseRoot, '/src/ios/AppDelegate+FirebasePlugin.m');
35
+ if (fs.existsSync(firebaseFile2)) {
36
+ try {
37
+ shell.rm('-Rf', firebaseFile2);
38
+ } catch (err) {
39
+ }
40
+ }
41
+
42
+ try {
43
+ shell.cp('-f', modifiedFile1, firebaseFile2);
44
+ } catch (err) {
45
+ }
46
+
47
+ if (SSL_PINNING === "true") {
48
+ console.log("appName : " + appName);
49
+ var get_info_plist = path.join(platformRoot, appName + '/' + appName + '-Info.plist');
50
+ if (fs.existsSync(get_info_plist)) {
51
+ console.log("ssl");
52
+ try {
53
+ fs.readFile(get_info_plist, 'utf8', function (err, data) {
54
+ if (err) {
55
+ throw new Error('Unable to find Plist: ' + err);
56
+ }
57
+ ///for removing SSL pinning
58
+ var SSL_PINNING_key = '<key>APPICE_SSL_PINNING</key>\n<true/>';
59
+ if (data.indexOf(SSL_PINNING_key) == -1) {
60
+ var result = data.replace('APPICE_SSL_PINNING', '');
61
+ fs.writeFile(get_info_plist, result, 'utf8', function (err) {
62
+ if (err) {
63
+ throw new Error('Unable to write into Plist: ' + err);
64
+ }
65
+ });
66
+ }
67
+ });
68
+ }
69
+ catch (err) {
70
+ }
71
+ }
72
+
73
+ }
75
74
  }
@@ -0,0 +1,177 @@
1
+ package com.appice.cordova;
2
+
3
+ import android.app.PendingIntent;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.os.Build;
7
+ import android.util.Log;
8
+
9
+ import androidx.annotation.NonNull;
10
+ import com.google.firebase.messaging.RemoteMessage;
11
+ import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService;
12
+ import com.ibm.mobilefirstplatform.clientsdk.android.push.internal.MFPInternalPushMessage;
13
+ import org.json.JSONObject;
14
+
15
+ import java.util.Map;
16
+
17
+ import semusi.activitysdk.ContextSdk;
18
+ import semusi.context.utility.Utility;
19
+
20
+ /* import path for MainActivity */
21
+
22
+
23
+ /*=============================*/
24
+
25
+ public class AppICEMFPPush extends MFPPushIntentService {
26
+ private static final String TAG = AppICEMFPPush.class.getSimpleName();
27
+ private static final String ACTION = "com.appice.campaignEvent";
28
+ private static final String PUSH_PAYLOAD = "ai_content";
29
+ private static final String MESSAGE = "message";
30
+ private static final String EXTERNAL_TYPE = "et";
31
+ private static final String DEEPLINK = "dl";
32
+ private static final String LANDING_PAGE = "lp";
33
+
34
+ @Override
35
+ public void onMessageReceived(RemoteMessage message) {
36
+ if (message != null)
37
+ onMessageReceived(message, null, null, getApplicationContext());
38
+ }
39
+
40
+ public void onMessageReceived(RemoteMessage message, PendingIntent createPendingIntent, PendingIntent deletePendingIntent, Context context) {
41
+ Map<String, String> data = message.getData();
42
+ MFPPushIntentService mfpPushIntentService = new MFPPushIntentService();
43
+ boolean isAppICEPayload = ContextSdk.isAppICENotification(message);
44
+ int collapseId = -1;
45
+ JSONObject payload = null;
46
+
47
+ if (isAppICEPayload && !checkIfPayloadHaveExternalUrl(message)) {
48
+ ContextSdk.handleAppICEPush(message, createPendingIntent(data.get(MESSAGE), context), deletePendingIntent(context), context);
49
+ } else if (isAppICEPayload && checkIfPayloadHaveExternalUrl(message)) {
50
+ ContextSdk.handleAppICEPush(message, context);
51
+ } else {
52
+
53
+ try {
54
+ JSONObject dataPayload = new JSONObject(data);
55
+ if (dataPayload != null) {
56
+ MFPInternalPushMessage recMessage = new MFPInternalPushMessage(dataPayload);
57
+ payload = new JSONObject(recMessage.getPayload());
58
+ if (payload != null && payload.has("collapseId")) {
59
+ collapseId = payload.optInt("collapseId");
60
+ }
61
+ }
62
+ } catch (Exception e) {
63
+ Log.e(TAG, "onMessageReceived: error ", e);
64
+ }
65
+
66
+ try {
67
+ if (collapseId != -1) {
68
+ mfpPushIntentService.onNotificationReceived(data, collapseId);
69
+ } else {
70
+ super.onMessageReceived(message);
71
+ }
72
+ } catch (Exception e) {
73
+ Log.e(TAG, "onMessageReceived: error", e);
74
+ }
75
+ }
76
+ }
77
+
78
+ @Override
79
+ public void onNewToken(@NonNull String s) {
80
+ super.onNewToken(s);
81
+ ContextSdk.checkIfDeviceRegisterToFCM(getApplicationContext());
82
+ }
83
+
84
+
85
+ /*======================================
86
+ * define your launch activity here
87
+ * also do the import for that activity for ex : import com.appice.sample.MainActivity;
88
+ * uncomment this try block
89
+ ========================================*/
90
+
91
+ public static PendingIntent createPendingIntent(String message, Context mContext) {
92
+ PendingIntent pendingIntent = null;
93
+ // uncomment this if you are using MFP service
94
+ // pendingIntent= internalCreatePendingIntent(message, mContext);
95
+ return pendingIntent;
96
+ }
97
+
98
+ public static PendingIntent deletePendingIntent(Context mContext) {
99
+ PendingIntent pendingIntent = null;
100
+
101
+ // uncomment this if you are using MFP service
102
+ //pendingIntent = internalDeletePendingIntent(mContext);
103
+ return pendingIntent;
104
+ }
105
+
106
+ //================================
107
+ // internal helper fucntion
108
+ //================================
109
+ private static PendingIntent internalCreatePendingIntent(String message, Context mContext){
110
+ try {
111
+ // please use your launch activity here
112
+ Intent clickIntent = new Intent(mContext, MainActivity.class);
113
+
114
+ final Intent newIntent = new Intent();
115
+ newIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
116
+ newIntent.setAction(ACTION);
117
+ clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
118
+ | Intent.FLAG_ACTIVITY_CLEAR_TOP
119
+ | Intent.FLAG_ACTIVITY_SINGLE_TOP);
120
+ newIntent.putExtra(PUSH_PAYLOAD, message);
121
+ Utility.sendEventToListener(mContext, newIntent);
122
+ return PendingIntent.getActivity(
123
+ mContext, 1, clickIntent, getPendingIntentFlags());
124
+ } catch (Throwable e) {
125
+ Log.e(TAG, "createPendingIntent: error ",e );
126
+ }
127
+ return null;
128
+ }
129
+
130
+ public static PendingIntent internalDeletePendingIntent(Context mContext) {
131
+ try {
132
+ // please use your launch activity here
133
+ Intent clickIntent = new Intent(mContext, MainActivity.class);
134
+
135
+ clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
136
+ return PendingIntent.getActivity(mContext, 1, clickIntent,
137
+ getPendingIntentFlags());
138
+ }catch (Throwable t){
139
+ Log.e(TAG, "deletePendingIntent: error ",t );
140
+ }
141
+ return null;
142
+ }
143
+
144
+ private static int getPendingIntentFlags(){
145
+ int flag;
146
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
147
+ flag = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE;
148
+ } else {
149
+ flag = PendingIntent.FLAG_UPDATE_CURRENT;
150
+ }
151
+
152
+ return flag;
153
+ }
154
+
155
+ private boolean checkIfPayloadHaveExternalUrl(RemoteMessage message) {
156
+ Map<String, String> map = message.getData();
157
+
158
+ try {
159
+ if (map != null) {
160
+ String messageStr = map.get(MESSAGE);
161
+ if (messageStr != null && messageStr.length() > 0) {
162
+ JSONObject messageObj = new JSONObject(messageStr);
163
+ String type = messageObj.optString(EXTERNAL_TYPE);
164
+ if (type.equalsIgnoreCase(DEEPLINK)) {
165
+ return false;
166
+ }
167
+ if (type.equalsIgnoreCase(LANDING_PAGE)) {
168
+ return true;
169
+ }
170
+ }
171
+ }
172
+ } catch (Throwable t) {
173
+ Log.e(TAG, "checkIfPayloadHaveExternalUrl: error ", t);
174
+ }
175
+ return false;
176
+ }
177
+ }