@woosmap/react-native-plugin-geofencing 0.1.27 → 0.2.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.
Files changed (34) hide show
  1. package/android/build.gradle +5 -5
  2. package/android/src/main/java/com/reactnativeplugingeofencing/AbstractPushHelper.java +7 -0
  3. package/android/src/main/java/com/reactnativeplugingeofencing/AirshipPushHelper.java +157 -0
  4. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +4 -0
  5. package/android/src/main/java/com/reactnativeplugingeofencing/WoosRegionReadyListener.java +8 -1
  6. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +1 -0
  7. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +17 -0
  8. package/ios/AirshipEvents.swift +48 -12
  9. package/ios/PluginGeofencing.swift +64 -54
  10. package/ios/WoosmapGeofenceService.swift +14 -13
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/internal/Location.js.map +1 -1
  13. package/lib/commonjs/internal/Poi.js.map +1 -1
  14. package/lib/commonjs/internal/Region.js.map +1 -1
  15. package/lib/commonjs/internal/Visit.js.map +1 -1
  16. package/lib/commonjs/internal/Zoi.js.map +1 -1
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/module/internal/Location.js.map +1 -1
  19. package/lib/module/internal/Poi.js.map +1 -1
  20. package/lib/module/internal/Region.js.map +1 -1
  21. package/lib/module/internal/Visit.js.map +1 -1
  22. package/lib/module/internal/Zoi.js.map +1 -1
  23. package/package.json +1 -4
  24. package/react-native-plugin-geofencing.podspec +9 -2
  25. package/src/index.tsx +0 -375
  26. package/src/internal/Airship.tsx +0 -24
  27. package/src/internal/Location.tsx +0 -46
  28. package/src/internal/MarketingCloud.tsx +0 -24
  29. package/src/internal/Poi.tsx +0 -107
  30. package/src/internal/Region.tsx +0 -66
  31. package/src/internal/Visit.tsx +0 -49
  32. package/src/internal/Zoi.tsx +0 -107
  33. package/src/internal/nativeInterface.tsx +0 -8
  34. package/src/internal/types.tsx +0 -20
@@ -19,10 +19,10 @@ def safeExtGet(prop, fallback) {
19
19
  }
20
20
 
21
21
  android {
22
- compileSdkVersion safeExtGet('PluginGeofencing_compileSdkVersion', 29)
22
+ compileSdkVersion safeExtGet('PluginGeofencing_compileSdkVersion', 33)
23
23
  defaultConfig {
24
24
  minSdkVersion safeExtGet('PluginGeofencing_minSdkVersion', 21)
25
- targetSdkVersion safeExtGet('PluginGeofencing_targetSdkVersion', 29)
25
+ targetSdkVersion safeExtGet('PluginGeofencing_targetSdkVersion', 33)
26
26
  versionCode 1
27
27
  versionName "1.0"
28
28
 
@@ -57,11 +57,11 @@ repositories {
57
57
  dependencies {
58
58
  //noinspection GradleDynamicVersion
59
59
  implementation "com.facebook.react:react-native:+" // From node_modules
60
- implementation 'com.google.android.gms:play-services-location:18.0.0'
60
+ implementation 'com.google.android.gms:play-services-location:21.0.1'
61
61
  implementation 'com.google.code.gson:gson:2.8.8'
62
62
  implementation "com.github.woosmap:geofencing-core-android-sdk:core_geofence_2.+"
63
- implementation("com.webgeoservices.woosmapgeofencing:woosmap-mobile-sdk:3.+")
64
- implementation 'com.google.android.gms:play-services-maps:17.0.0'
63
+ implementation("com.webgeoservices.woosmapgeofencing:woosmap-mobile-sdk:3.0.11")
64
+ implementation 'com.google.android.gms:play-services-maps:18.1.0'
65
65
  implementation 'androidx.room:room-runtime:2.2.4'
66
66
  annotationProcessor 'androidx.room:room-compiler:2.2.4'
67
67
  implementation 'androidx.room:room-rxjava2:2.2.4'
@@ -0,0 +1,7 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import java.util.Map;
4
+
5
+ public interface AbstractPushHelper {
6
+ void pushDataToCloud(Map<String, Object> data);
7
+ }
@@ -0,0 +1,157 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.content.Context;
4
+ import android.util.Log;
5
+
6
+ import com.webgeoservices.woosmapgeofencing.SearchAPIDataModel.SearchAPIResponseItem;
7
+ import com.webgeoservices.woosmapgeofencingcore.database.POI;
8
+ import com.webgeoservices.woosmapgeofencingcore.database.POIsDAO;
9
+ import com.webgeoservices.woosmapgeofencingcore.database.RegionLog;
10
+ import com.webgeoservices.woosmapgeofencingcore.database.WoosmapDb;
11
+
12
+ import java.lang.reflect.Constructor;
13
+ import java.lang.reflect.Method;
14
+ import java.text.SimpleDateFormat;
15
+ import java.util.HashMap;
16
+ import java.util.Map;
17
+ import java.util.TimeZone;
18
+ import org.json.JSONException;
19
+ import org.json.JSONObject;
20
+
21
+ public class AirshipPushHelper implements AbstractPushHelper {
22
+ SimpleDateFormat displayDateFormatAirship;
23
+ WoosmapDb db;
24
+ private static final String TAG = "AirshipPushHelper";
25
+ public AirshipPushHelper(Context context){
26
+ displayDateFormatAirship = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss'Z'");
27
+ displayDateFormatAirship.setTimeZone(TimeZone.getTimeZone("UTC"));
28
+ db = WoosmapDb.getInstance(context);
29
+ }
30
+
31
+ @Override
32
+ public void pushDataToCloud(Map<String, Object> data) {
33
+ try{
34
+ if (data.containsKey("event")){
35
+ Class<?> builderClass = Class.forName("com.urbanairship.analytics.CustomEvent$Builder");
36
+ Constructor<?> cons = builderClass.getConstructor(String.class);
37
+ Object builderInstance = cons.newInstance(data.get("event"));
38
+
39
+ Method addProp;
40
+ Object keyData;
41
+ String key;
42
+ Class type;
43
+ for (Map.Entry<String, Object> entry : data.entrySet()) {
44
+ key = entry.getKey();
45
+ keyData = entry.getValue();
46
+ type = keyData.getClass();
47
+ if (type.getName().equals("java.lang.Double")){
48
+ type = double.class;
49
+ }
50
+ if (type.getName().equals("java.lang.Integer")){
51
+ type = int.class;
52
+ }
53
+ if (type.getName().equals("java.lang.Boolean")){
54
+ type = boolean.class;
55
+ }
56
+ if (type.getName().equals("java.lang.Long")){
57
+ type = long.class;
58
+ }
59
+ addProp = builderClass.getMethod("addProperty", String.class, type);
60
+ addProp.invoke(builderInstance,key, keyData);
61
+ }
62
+
63
+ Method build = builderClass.getMethod("build");
64
+ build.invoke(builderInstance);
65
+
66
+ Class<?> eventClass = Class.forName("com.urbanairship.analytics.CustomEvent");
67
+ Constructor<?>[] consList = eventClass.getDeclaredConstructors();
68
+ for(Constructor<?> con : consList){
69
+ try{
70
+ con.setAccessible(true);
71
+ Object eventInstance = con.newInstance(builderInstance);
72
+ Method track = eventClass.getMethod("track");
73
+ Object trackResult = track.invoke(eventInstance);
74
+ Log.d(TAG,"event tracked");
75
+ continue;
76
+ }
77
+ catch (Exception ex) {
78
+ Log.e(TAG, ex.toString());
79
+ }
80
+ }
81
+ }
82
+ }
83
+ catch (Exception ex){
84
+ Log.e(TAG, ex.toString());
85
+ }
86
+ }
87
+
88
+ protected HashMap<String, Object> getAirshipData(RegionLog regionLog) {
89
+ HashMap<String, Object> data = new HashMap<>();
90
+
91
+ String eventName = regionLog.identifier.contains("HOME") || regionLog.identifier.contains("WORK")
92
+ ? "android_woos_zoi_classified_"
93
+ : "android_woos_geofence_";
94
+
95
+ // Create and name an event
96
+ eventName += regionLog.isCurrentPositionInside ? "entered_event" : "exited_event";
97
+ if (regionLog.idStore.isEmpty()) {
98
+ data.put("event", eventName);
99
+ data.put("id", regionLog.id);
100
+ data.put("date", displayDateFormatAirship.format(regionLog.dateTime));
101
+ data.put("radius", regionLog.radius);
102
+ data.put("latitude", regionLog.lat);
103
+ data.put("longitude", regionLog.lng);
104
+ } else {
105
+
106
+ POI poi = this.db.getPOIsDAO().getPOIbyStoreId(regionLog.idStore);
107
+ if (poi != null) {
108
+ HashMap<String, Object> poiData = setDataAirshipPOI(poi);
109
+ if (poiData != null) {
110
+ data.putAll(poiData);
111
+ }
112
+ }
113
+ data.put("date", displayDateFormatAirship.format(regionLog.dateTime));
114
+ data.put("event", eventName);
115
+ data.put("id", regionLog.id);
116
+ }
117
+ return data;
118
+ }
119
+
120
+ private HashMap<String, Object> setDataAirshipPOI(POI POIaround) {
121
+ HashMap<String, Object> data = new HashMap<>();
122
+ data.put("event", "woos_poi_event");
123
+ data.put("city", POIaround.city);
124
+ data.put("zipCode", POIaround.zipCode);
125
+ data.put("date", displayDateFormatAirship.format(POIaround.dateTime));
126
+ data.put("distance", POIaround.distance);
127
+ data.put("idStore", POIaround.idStore);
128
+ data.put("name", POIaround.name);
129
+ data.put("lat", POIaround.lat);
130
+ data.put("lng", POIaround.lng);
131
+ data.put("radius", POIaround.radius);
132
+ data.put("address", POIaround.address);
133
+ data.put("contact", POIaround.contact);
134
+ data.put("types", POIaround.types);
135
+ data.put("tags", POIaround.tags);
136
+ if (!"null".equals(POIaround.countryCode)) {
137
+ data.put("country_code", POIaround.countryCode);
138
+ }
139
+ data.put("openNow", POIaround.openNow);
140
+
141
+ // User Properties
142
+ try {
143
+ JSONObject json = new JSONObject(POIaround.data);
144
+ HashMap<String, Object> userPropertiesFiltered = SearchAPIResponseItem.getUserProperties(json, POIaround.idStore);
145
+ if (userPropertiesFiltered != null) {
146
+ for (Map.Entry<String, Object> entry : userPropertiesFiltered.entrySet()) {
147
+ data.put("user_properties_" + entry.getKey(), entry.getValue());
148
+ }
149
+ }
150
+ } catch (JSONException e) {
151
+ e.printStackTrace();
152
+ }
153
+
154
+ return data;
155
+ }
156
+
157
+ }
@@ -97,6 +97,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
97
97
  if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
98
98
  WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
99
99
  }
100
+
101
+ if (map.hasKey(WoosmapMessageAndKey.enableAirshipConnectorKey)){
102
+ WoosmapUtil.setEnableAishipConnector(map.getBoolean(WoosmapMessageAndKey.enableAirshipConnectorKey), getReactApplicationContext());
103
+ }
100
104
  // Set the Delay of Duration data
101
105
  WoosmapSettings.numberOfDayDataDuration = 30;
102
106
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -11,6 +11,8 @@ import com.webgeoservices.woosmapgeofencing.Woosmap;
11
11
  import com.webgeoservices.woosmapgeofencingcore.database.Region;
12
12
  import com.webgeoservices.woosmapgeofencingcore.database.RegionLog;
13
13
 
14
+ import java.util.HashMap;
15
+
14
16
  /***
15
17
  * Implements Woosmap Region callbacks
16
18
  */
@@ -32,6 +34,12 @@ public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woos
32
34
  public void RegionLogReadyCallback(RegionLog regionLog) {
33
35
  try {
34
36
  ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
37
+ if (WoosmapUtil.getEnableAishipConnector(context)){
38
+ //Do the airship push here.
39
+ AirshipPushHelper airshipPushHelper = new AirshipPushHelper(context);
40
+ HashMap<String, Object> data = airshipPushHelper.getAirshipData(regionLog);
41
+ airshipPushHelper.pushDataToCloud(data);
42
+ }
35
43
  reactNativeHost = reactApplication.getReactNativeHost();
36
44
  sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(regionLog));
37
45
  }catch (Exception ex){
@@ -41,6 +49,5 @@ public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woos
41
49
 
42
50
  @Override
43
51
  public void RegionReadyCallback(Region region) {
44
-
45
52
  }
46
53
  }
@@ -48,6 +48,7 @@ public class WoosmapMessageAndKey {
48
48
  protected static String invalidProfileFile = "Invalid profile file";
49
49
  protected static String localMode="local";
50
50
  protected static String externalMode="external";
51
+ protected static String enableAirshipConnectorKey="enableAirshipConnector";
51
52
 
52
53
 
53
54
 
@@ -1,5 +1,9 @@
1
1
  package com.reactnativeplugingeofencing;
2
2
 
3
+ import static android.content.Context.MODE_PRIVATE;
4
+
5
+ import android.content.Context;
6
+ import android.content.SharedPreferences;
3
7
  import android.location.Location;
4
8
  import android.util.Log;
5
9
 
@@ -9,6 +13,7 @@ import com.facebook.react.bridge.WritableArray;
9
13
  import com.facebook.react.bridge.WritableMap;
10
14
  import com.facebook.react.bridge.WritableNativeArray;
11
15
  import com.facebook.react.bridge.WritableNativeMap;
16
+ import com.webgeoservices.woosmapgeofencing.WoosmapSettings;
12
17
  import com.webgeoservices.woosmapgeofencingcore.database.MovingPosition;
13
18
  import com.webgeoservices.woosmapgeofencingcore.database.POI;
14
19
  import com.webgeoservices.woosmapgeofencingcore.database.Region;
@@ -187,5 +192,17 @@ public class WoosmapUtil {
187
192
  }
188
193
  }
189
194
 
195
+ protected static void setEnableAishipConnector(boolean value, Context context){
196
+ SharedPreferences mPrefs = context.getSharedPreferences("WGSGeofencingReactPref", MODE_PRIVATE);
197
+ SharedPreferences.Editor prefsEditor = mPrefs.edit();
198
+ prefsEditor.clear();
199
+ prefsEditor.putBoolean(WoosmapMessageAndKey.enableAirshipConnectorKey, value);
200
+ prefsEditor.commit();
201
+ }
202
+
203
+ protected static boolean getEnableAishipConnector(Context context){
204
+ SharedPreferences mPrefs = context.getSharedPreferences("WGSGeofencingReactPref", MODE_PRIVATE);
205
+ return mPrefs.getBoolean(WoosmapMessageAndKey.enableAirshipConnectorKey, false);
206
+ }
190
207
 
191
208
  }
@@ -7,8 +7,8 @@
7
7
  import Foundation
8
8
  import CoreLocation
9
9
  import WoosmapGeofencing
10
- #if canImport(AirshipCore)
11
- import AirshipCore
10
+ #if canImport(AirshipKit)
11
+ import AirshipKit
12
12
  #endif
13
13
 
14
14
  class AirshipData {
@@ -23,47 +23,83 @@ class AirshipData {
23
23
 
24
24
  public class AirshipEvents: AirshipEventsDelegate {
25
25
 
26
- public init() {}
26
+ var enableAirshipCallback: Bool = false
27
+ public init() {
28
+ let defaults = UserDefaults.standard
29
+ enableAirshipCallback = defaults.bool(forKey: "WoosmapGeofenceService.AirshipCallbackEnable")
30
+ }
27
31
 
28
32
  public func regionEnterEvent(regionEvent: [String: Any], eventName: String) {
29
- #if canImport(AirshipCore)
33
+ #if canImport(AirshipKit)
30
34
  var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
31
35
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
32
- #endif
36
+ if(enableAirshipCallback){
37
+ let event = CustomEvent(name: eventName, value: 1)
38
+ event.properties = regionEvent
39
+ event.track()
40
+ }
41
+ #else
42
+ print("No Airship SDK")
43
+ #endif
33
44
  }
34
45
 
35
46
  public func regionExitEvent(regionEvent: [String: Any], eventName: String) {
36
- #if canImport(AirshipCore)
47
+ #if canImport(AirshipKit)
37
48
  var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
38
49
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
50
+ if(enableAirshipCallback){
51
+ let event = CustomEvent(name: eventName, value: 1)
52
+ event.properties = regionEvent
53
+ event.track()
54
+ }
39
55
  #endif
40
56
  }
41
57
 
42
58
  public func visitEvent(visitEvent: [String: Any], eventName: String) {
43
- #if canImport(AirshipCore)
44
- var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
59
+ #if canImport(AirshipKit)
60
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: visitEvent)
45
61
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
62
+ if(enableAirshipCallback){
63
+ let event = CustomEvent(name: eventName, value: 1)
64
+ event.properties = visitEvent
65
+ event.track()
66
+ }
46
67
  #endif
47
68
  }
48
69
 
49
70
  public func poiEvent(POIEvent: [String: Any], eventName: String) {
50
- #if canImport(AirshipCore)
51
- var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
71
+ #if canImport(AirshipKit)
72
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: POIEvent)
52
73
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
74
+ if(enableAirshipCallback){
75
+ let event = CustomEvent(name: eventName, value: 1)
76
+ event.properties = POIEvent
77
+ event.track()
78
+ }
53
79
  #endif
54
80
  }
55
81
 
56
82
  public func ZOIclassifiedEnter(regionEvent: [String: Any], eventName: String) {
57
- #if canImport(AirshipCore)
83
+ #if canImport(AirshipKit)
58
84
  var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
59
85
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
86
+ if(enableAirshipCallback){
87
+ let event = CustomEvent(name: eventName, value: 1)
88
+ event.properties = regionEvent
89
+ event.track()
90
+ }
60
91
  #endif
61
92
  }
62
93
 
63
94
  public func ZOIclassifiedExit(regionEvent: [String: Any], eventName: String) {
64
- #if canImport(AirshipCore)
95
+ #if canImport(AirshipKit)
65
96
  var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
66
97
  NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
98
+ if(enableAirshipCallback){
99
+ let event = CustomEvent(name: eventName, value: 1)
100
+ event.properties = regionEvent
101
+ event.track()
102
+ }
67
103
  #endif
68
104
  }
69
105
  }