cordova-plugin-insider 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-insider",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "A plugin that you can use Insider SDK with Cordova and Ionic",
5
5
  "cordova_name": "Insider Cordova Plugin",
6
6
  "cordova": {
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-insider" version="2.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <plugin id="cordova-plugin-insider" version="2.1.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
3
3
  <name>Insider</name>
4
4
  <description>Insider Cordova Plugin</description>
5
5
  <keywords>insider,cordova,cordova-ios,cordova-android</keywords>
@@ -70,8 +70,8 @@
70
70
  <source url="https://cdn.cocoapods.org/" />
71
71
  </config>
72
72
  <pods use-frameworks="true">
73
- <pod name="InsiderMobile" spec="13.4.0" />
74
- <pod name="InsiderGeofence" spec="1.1.0" />
73
+ <pod name="InsiderMobile" spec="13.4.3" />
74
+ <pod name="InsiderGeofence" spec="1.1.3" />
75
75
  <pod name="InsiderHybrid" spec="1.4.0" />
76
76
  </pods>
77
77
  </podspec>
@@ -11,7 +11,6 @@ import android.content.pm.PackageManager;
11
11
  import android.os.Bundle;
12
12
  import android.os.Handler;
13
13
  import android.os.Looper;
14
- import android.util.Log;
15
14
 
16
15
  import com.fasterxml.jackson.databind.ObjectMapper;
17
16
  import com.google.firebase.messaging.RemoteMessage;
@@ -28,6 +27,7 @@ import com.useinsider.insider.RecommendationEngine;
28
27
  import com.useinsider.insiderhybrid.InsiderHybrid;
29
28
  import com.useinsider.insiderhybrid.InsiderHybridUtils;
30
29
  import com.useinsider.insiderhybrid.constants.InsiderHybridMethods;
30
+ import com.useinsider.insider.InsiderIDListener;
31
31
 
32
32
  import org.apache.cordova.CallbackContext;
33
33
  import org.apache.cordova.CordovaPlugin;
@@ -49,6 +49,8 @@ import java.util.Map;
49
49
  public class InsiderPlugin extends CordovaPlugin {
50
50
  private boolean isCoreInitialized = false;
51
51
 
52
+ private InsiderIDListener insiderIDListener;
53
+
52
54
  @Override
53
55
  protected void pluginInitialize() {
54
56
  super.initialize(cordova, webView);
@@ -99,6 +101,23 @@ public class InsiderPlugin extends CordovaPlugin {
99
101
  webView.loadUrl("javascript:cordova.fireDocumentEvent('ins_notification_handle'," + json + ");");
100
102
  }
101
103
 
104
+ public void sendInsiderIDToJS(String insiderIDObject) {
105
+ try {
106
+ cordova.getActivity().runOnUiThread(new Runnable() {
107
+ @Override
108
+ public void run() {
109
+ try {
110
+ webView.loadUrl("javascript:cordova.fireDocumentEvent('ins_insider_id_listener'," + insiderIDObject + ");");
111
+ } catch (Exception e) {
112
+ Insider.Instance.putException(e);
113
+ }
114
+ }
115
+ });
116
+ } catch (Exception e) {
117
+ Insider.Instance.putException(e);
118
+ }
119
+ }
120
+
102
121
  @Override
103
122
  public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
104
123
  if (args == null) {
@@ -649,6 +668,22 @@ public class InsiderPlugin extends CordovaPlugin {
649
668
  return false;
650
669
 
651
670
  Insider.Instance.getCurrentUser().setPhoneNumber(args.getString(0));
671
+ } else if (action.equals("getInsiderID")) {
672
+ callbackSuccess(callbackContext, Insider.Instance.getInsiderID());
673
+ } else if (action.equals("registerInsiderIDListener")) {
674
+ if (insiderIDListener == null) {
675
+ insiderIDListener = new InsiderIDListener() {
676
+ @Override
677
+ public void onUpdated(String insiderID) {
678
+ String insiderIDJSONObject = "{ 'insiderID':'" + insiderID + "' }";
679
+
680
+ sendInsiderIDToJS(insiderIDJSONObject);
681
+ }
682
+ };
683
+
684
+
685
+ Insider.Instance.registerInsiderIDListener(insiderIDListener);
686
+ }
652
687
  } else {
653
688
  return false;
654
689
  }
@@ -16,7 +16,7 @@ android {
16
16
  }
17
17
 
18
18
  dependencies {
19
- implementation 'com.useinsider:insider:14.2.2'
19
+ implementation 'com.useinsider:insider:14.2.4'
20
20
  implementation 'com.useinsider:insiderhybrid:1.1.6'
21
21
 
22
22
  implementation 'com.fasterxml.jackson.core:jackson-core:2.12.4'
@@ -24,6 +24,7 @@ dependencies {
24
24
 
25
25
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
26
26
  implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
27
+ implementation 'androidx.security:security-crypto:1.1.0-alpha06'
27
28
 
28
29
  implementation 'com.google.android.gms:play-services-location:21.0.1'
29
30
  implementation 'com.google.firebase:firebase-messaging:23.0.5'
@@ -32,6 +33,4 @@ dependencies {
32
33
  implementation 'com.huawei.hms:push:6.5.0.300'
33
34
  implementation 'com.huawei.hms:ads-identifier:3.4.39.302'
34
35
  implementation 'com.huawei.hms:location:6.4.0.300'
35
-
36
- implementation 'androidx.security:security-crypto:1.1.0-alpha06'
37
36
  }
@@ -60,4 +60,6 @@
60
60
  - (void) signUpConfirmation:(CDVInvokedUrlCommand *)command;
61
61
  - (void) putException:(CDVInvokedUrlCommand *)command;
62
62
  - (void) handleNotification:(CDVInvokedUrlCommand *)command;
63
+ - (void) getInsiderID:(CDVInvokedUrlCommand *)command;
64
+ - (void) registerInsiderIDListener:(CDVInvokedUrlCommand *)command;
63
65
  @end
@@ -769,6 +769,37 @@
769
769
  }
770
770
  }
771
771
 
772
+ - (void)getInsiderID:(CDVInvokedUrlCommand *)command {
773
+ @try {
774
+ [self sendSuccessResultWithString:[Insider getInsiderID] andCommand:command];
775
+ } @catch (NSException *exception){
776
+ [Insider sendError:exception desc:@"Insider.m - getInsiderID"];
777
+
778
+ [self sendSuccessResultWithString:nil andCommand:command];
779
+ }
780
+ }
781
+
782
+ - (void)registerInsiderIDListener:(CDVInvokedUrlCommand *)command {
783
+ @try {
784
+ [Insider registerInsiderIDListenerWithSelector:@selector(insiderIDChangeListener:) sender:self];
785
+ } @catch (NSException *exception){
786
+ [Insider sendError:exception desc:@"Insider.m - registerInsiderIDListener"];
787
+ }
788
+ }
789
+
790
+ -(void)insiderIDChangeListener:(NSString *)insiderID {
791
+ @try {
792
+ if (insiderID == nil) return;
793
+
794
+ NSString *data = [NSString stringWithFormat:@"{""insiderID"":""'%@'""}", insiderID];
795
+ NSString *js = [NSString stringWithFormat:@"cordova.fireDocumentEvent('ins_insider_id_listener',%@);", data];
796
+
797
+ [self.commandDelegate evalJs:js];
798
+ } @catch (NSException *e){
799
+ [Insider sendError:e desc:[NSString stringWithFormat:@"%s:%d", __func__, __LINE__]];
800
+ }
801
+ }
802
+
772
803
  - (void)putException:(CDVInvokedUrlCommand *)command {
773
804
  @try {
774
805
  if (![command.arguments objectAtIndex:0]) return;
package/www/Constants.js CHANGED
@@ -64,6 +64,8 @@ module.exports = {
64
64
  SET_ACTIVE_FOREGROUND_PUSH_VIEW: 'setActiveForegroundPushView',
65
65
  SET_FOREGROUND_PUSH_CALLBACK: 'setForegroundPushCallback',
66
66
  HANDLE_NOTIFICATION: 'handleNotification',
67
+ GET_INSIDER_ID: 'getInsiderID',
68
+ REGISTER_INSIDER_ID_LISTENER: 'registerInsiderIDListener',
67
69
  // Event
68
70
  TAG_EVENT: 'tagEvent',
69
71
  // Product Attribute
@@ -86,5 +88,5 @@ module.exports = {
86
88
  // Reinit
87
89
  REINIT_WITH_PARTNER_NAME: 'reinitWithPartnerName',
88
90
  // SDK Version
89
- SDK_VERSION: 'CDV-2.0.0',
91
+ SDK_VERSION: 'CDV-2.1.1',
90
92
  };
@@ -519,6 +519,30 @@ class InsiderPlugin {
519
519
  Utils.asyncExec(InsiderConstants.CLASS, InsiderConstants.PUT_ERROR_LOG, [Utils.generateJSONErrorString(error)]);
520
520
  }
521
521
  }
522
+
523
+ getInsiderID = () => {
524
+ try {
525
+ return Utils.asyncExec(InsiderConstants.CLASS, InsiderConstants.GET_INSIDER_ID, []);
526
+ } catch (error) {
527
+ Utils.asyncExec(InsiderConstants.CLASS, InsiderConstants.PUT_ERROR_LOG, [Utils.generateJSONErrorString(error)]);
528
+
529
+ return null;
530
+ }
531
+ }
532
+
533
+ registerInsiderIDListener = (insiderIDCallback) => {
534
+ try {
535
+ Utils.asyncExec(InsiderConstants.CLASS, InsiderConstants.REGISTER_INSIDER_ID_LISTENER, []);
536
+
537
+ document.addEventListener('ins_insider_id_listener', (event) => {
538
+ if (event.insiderID) {
539
+ insiderIDCallback(event.insiderID);
540
+ }
541
+ }, false);
542
+ } catch (error) {
543
+ Utils.asyncExec(InsiderConstants.CLASS, InsiderConstants.PUT_ERROR_LOG, [Utils.generateJSONErrorString(error)]);
544
+ }
545
+ }
522
546
  }
523
547
 
524
548
  module.exports = new InsiderPlugin();