@woosmap/react-native-plugin-geofencing 0.1.4 → 0.1.7

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 (78) hide show
  1. package/README.md +219 -20
  2. package/android/build.gradle +7 -0
  3. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +328 -35
  4. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +20 -3
  5. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapTask.java +299 -0
  6. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +108 -0
  7. package/ios/DataDistance.swift +14 -23
  8. package/ios/DataLocation.swift +16 -0
  9. package/ios/DataPOI.swift +11 -0
  10. package/ios/DataRegion.swift +32 -29
  11. package/ios/MarketingCloudEvents.swift +6 -6
  12. package/ios/PluginGeofencing.m +43 -0
  13. package/ios/PluginGeofencing.swift +380 -26
  14. package/ios/WoosmapGeofenceMessage.swift +12 -0
  15. package/ios/WoosmapGeofenceService.swift +203 -30
  16. package/lib/commonjs/index.js +171 -68
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/{Airship.js → internal/Airship.js} +0 -0
  19. package/lib/commonjs/{Airship.js.map → internal/Airship.js.map} +0 -0
  20. package/lib/commonjs/{Location.js → internal/Location.js} +0 -0
  21. package/lib/commonjs/{Location.js.map → internal/Location.js.map} +0 -0
  22. package/lib/commonjs/{MarketingCloud.js → internal/MarketingCloud.js} +0 -0
  23. package/lib/commonjs/{MarketingCloud.js.map → internal/MarketingCloud.js.map} +0 -0
  24. package/lib/{module → commonjs/internal}/Poi.js +10 -1
  25. package/lib/commonjs/internal/Poi.js.map +1 -0
  26. package/lib/commonjs/{Region.js → internal/Region.js} +0 -0
  27. package/lib/commonjs/{Region.js.map → internal/Region.js.map} +0 -0
  28. package/lib/commonjs/{Visit.js → internal/Visit.js} +0 -0
  29. package/lib/commonjs/{Visit.js.map → internal/Visit.js.map} +0 -0
  30. package/lib/commonjs/{Zoi.js → internal/Zoi.js} +0 -0
  31. package/lib/commonjs/{Zoi.js.map → internal/Zoi.js.map} +0 -0
  32. package/lib/commonjs/internal/nativeInterface.js +18 -0
  33. package/lib/commonjs/internal/nativeInterface.js.map +1 -0
  34. package/lib/commonjs/internal/types.js +2 -0
  35. package/lib/commonjs/internal/types.js.map +1 -0
  36. package/lib/module/index.js +155 -53
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/{Airship.js → internal/Airship.js} +0 -0
  39. package/lib/module/{Airship.js.map → internal/Airship.js.map} +0 -0
  40. package/lib/module/{Location.js → internal/Location.js} +0 -0
  41. package/lib/module/{Location.js.map → internal/Location.js.map} +0 -0
  42. package/lib/module/{MarketingCloud.js → internal/MarketingCloud.js} +0 -0
  43. package/lib/module/{MarketingCloud.js.map → internal/MarketingCloud.js.map} +0 -0
  44. package/lib/{commonjs → module/internal}/Poi.js +2 -3
  45. package/lib/module/internal/Poi.js.map +1 -0
  46. package/lib/module/{Region.js → internal/Region.js} +0 -0
  47. package/lib/module/{Region.js.map → internal/Region.js.map} +0 -0
  48. package/lib/module/{Visit.js → internal/Visit.js} +0 -0
  49. package/lib/module/{Visit.js.map → internal/Visit.js.map} +0 -0
  50. package/lib/module/{Zoi.js → internal/Zoi.js} +0 -0
  51. package/lib/module/{Zoi.js.map → internal/Zoi.js.map} +0 -0
  52. package/lib/module/internal/nativeInterface.js +9 -0
  53. package/lib/module/internal/nativeInterface.js.map +1 -0
  54. package/lib/module/internal/types.js +2 -0
  55. package/lib/module/internal/types.js.map +1 -0
  56. package/lib/typescript/index.d.ts +63 -4
  57. package/lib/typescript/{Airship.d.ts → internal/Airship.d.ts} +0 -0
  58. package/lib/typescript/{Location.d.ts → internal/Location.d.ts} +0 -0
  59. package/lib/typescript/{MarketingCloud.d.ts → internal/MarketingCloud.d.ts} +0 -0
  60. package/lib/typescript/{Poi.d.ts → internal/Poi.d.ts} +4 -2
  61. package/lib/typescript/{Region.d.ts → internal/Region.d.ts} +0 -0
  62. package/lib/typescript/{Visit.d.ts → internal/Visit.d.ts} +0 -0
  63. package/lib/typescript/{Zoi.d.ts → internal/Zoi.d.ts} +0 -0
  64. package/lib/typescript/internal/nativeInterface.d.ts +2 -0
  65. package/lib/typescript/internal/types.d.ts +18 -0
  66. package/package.json +1 -1
  67. package/src/index.tsx +173 -53
  68. package/src/{Airship.tsx → internal/Airship.tsx} +0 -0
  69. package/src/{Location.tsx → internal/Location.tsx} +0 -0
  70. package/src/{MarketingCloud.tsx → internal/MarketingCloud.tsx} +0 -0
  71. package/src/{Poi.tsx → internal/Poi.tsx} +4 -3
  72. package/src/{Region.tsx → internal/Region.tsx} +0 -0
  73. package/src/{Visit.tsx → internal/Visit.tsx} +0 -0
  74. package/src/{Zoi.tsx → internal/Zoi.tsx} +0 -0
  75. package/src/internal/nativeInterface.tsx +8 -0
  76. package/src/internal/types.tsx +20 -0
  77. package/lib/commonjs/Poi.js.map +0 -1
  78. package/lib/module/Poi.js.map +0 -1
@@ -0,0 +1,299 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.content.Context;
4
+ import android.os.Build;
5
+
6
+
7
+ import androidx.annotation.RequiresApi;
8
+
9
+
10
+ import com.facebook.react.bridge.Arguments;
11
+ import com.facebook.react.bridge.Promise;
12
+ import com.facebook.react.bridge.WritableArray;
13
+ import com.facebook.react.bridge.WritableNativeArray;
14
+ import com.google.android.gms.maps.model.LatLng;
15
+ import com.webgeoservices.woosmapgeofencing.Woosmap;
16
+ import com.webgeoservices.woosmapgeofencing.database.MovingPosition;
17
+ import com.webgeoservices.woosmapgeofencing.database.POI;
18
+ import com.webgeoservices.woosmapgeofencing.database.Region;
19
+ import com.webgeoservices.woosmapgeofencing.database.WoosmapDb;
20
+
21
+ import org.json.JSONObject;
22
+
23
+ import java.util.concurrent.CompletableFuture;
24
+ import java.util.concurrent.CompletionException;
25
+ import java.util.function.Supplier;
26
+
27
+ public class WoosmapTask {
28
+ private static WoosmapTask _instance = null;
29
+ private final Context context;
30
+
31
+ public static WoosmapTask getInstance(Context context) {
32
+ if (_instance == null) {
33
+ _instance = new WoosmapTask(context);
34
+ }
35
+ return _instance;
36
+ }
37
+
38
+ private WoosmapTask(Context context) {
39
+ this.context = context;
40
+ }
41
+
42
+ @RequiresApi(api = Build.VERSION_CODES.N)
43
+ public void addRegion(final Region region, final Promise promise) {
44
+ CompletableFuture.supplyAsync(() -> {
45
+ try {
46
+ if ((!region.type.isEmpty()) && (!region.type.equalsIgnoreCase(WoosmapMessageAndKey.isochroneTypeKey) && !region.type.equalsIgnoreCase(WoosmapMessageAndKey.circleTypeKey))) {
47
+ throw new Exception(WoosmapMessageAndKey.validRegionTypeMessage);
48
+ }
49
+ if (region.idStore.isEmpty() && region.type.isEmpty()) {
50
+ Woosmap.getInstance().addGeofence(region.identifier, new LatLng(region.lat, region.lng), (float) region.radius);
51
+ } else if (!region.idStore.isEmpty() && region.type.isEmpty()) {
52
+ Woosmap.getInstance().addGeofence(region.identifier, new LatLng(region.lat, region.lng), (float) region.radius, region.idStore);
53
+ } else if (!region.type.isEmpty() && region.idStore.isEmpty()) {
54
+ Woosmap.getInstance().addGeofence(region.identifier, new LatLng(region.lat, region.lng), (float) region.radius, region.type);
55
+ } else {
56
+ Woosmap.getInstance().addGeofence(region.identifier, new LatLng(region.lat, region.lng), (float) region.radius, region.idStore, region.type);
57
+ }
58
+
59
+ } catch (Exception ex) {
60
+ throw new CompletionException(ex);
61
+ }
62
+ return region.identifier;
63
+ }).whenComplete((data, throwable) -> {
64
+ if (throwable != null) {
65
+ promise.reject(WoosmapMessageAndKey.errorCode, throwable.getMessage());
66
+ } else {
67
+ promise.resolve(data);
68
+ }
69
+ });
70
+ }
71
+
72
+ @RequiresApi(api = Build.VERSION_CODES.N)
73
+ public void enqueGetRegionsRequest(String regionID,Promise promise) {
74
+ CompletableFuture.supplyAsync(() -> {
75
+ try {
76
+ Region region;
77
+ region = WoosmapDb.getInstance(context).getRegionsDAO().getRegionFromId(regionID);
78
+ if(region!=null){
79
+ return WoosmapUtil.getRegionWritableMap(region);
80
+ }
81
+ } catch (Exception ex) {
82
+ throw new CompletionException(ex);
83
+ }
84
+ return null;
85
+ }).whenComplete((data, throwable) -> {
86
+ if (throwable == null) {
87
+ if(data==null){
88
+ promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.invalidRegionid);
89
+ }else {
90
+ promise.resolve(data);
91
+ }
92
+ } else {
93
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
94
+ }
95
+ });
96
+ }
97
+
98
+ @RequiresApi(api = Build.VERSION_CODES.N)
99
+ public void enqueGetRegionsRequest(Promise promise) {
100
+ CompletableFuture.supplyAsync(() -> {
101
+ try {
102
+ Region[] regions;
103
+ WritableArray array= Arguments.createArray();
104
+ regions = WoosmapDb.getInstance(context).getRegionsDAO().getAllRegions();
105
+ for (Region region : regions) {
106
+ array.pushMap(WoosmapUtil.getRegionWritableMap(region));
107
+ }
108
+ return array;
109
+ } catch (Exception ex) {
110
+ throw new CompletionException(ex);
111
+ }
112
+ }).whenComplete((data, throwable) -> {
113
+ if (throwable == null) {
114
+ promise.resolve(data);
115
+ } else {
116
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
117
+ }
118
+ });
119
+ }
120
+ @RequiresApi(api = Build.VERSION_CODES.N)
121
+ public void removeRegion(String regionId, final Promise promise){
122
+ CompletableFuture.supplyAsync((Supplier<Void>) () -> {
123
+ try{
124
+ if (!regionId.isEmpty()){
125
+ Woosmap.getInstance().removeGeofence(regionId);
126
+ WoosmapDb.getInstance(context).getRegionsDAO().deleteRegionFromId(regionId);
127
+ }
128
+ else{
129
+ Woosmap.getInstance().removeGeofence();
130
+ WoosmapDb.getInstance(context).getRegionsDAO().deleteAllRegions();
131
+ }
132
+ }
133
+ catch (Exception ex){
134
+ throw new CompletionException(ex);
135
+ }
136
+ return null;
137
+ }).whenComplete((unused, throwable) -> {
138
+ if (throwable==null){
139
+ promise.resolve(WoosmapMessageAndKey.deleteMessage);
140
+ }
141
+ else{
142
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
143
+ }
144
+ });
145
+ }
146
+
147
+ @RequiresApi(api = Build.VERSION_CODES.N)
148
+ public void removeAllPois(final Promise promise){
149
+ CompletableFuture.supplyAsync((Supplier<Void>) () -> {
150
+ try{
151
+ WoosmapDb.getInstance(context).getPOIsDAO().deleteAllPOIs();
152
+ }
153
+ catch (Exception ex){
154
+ throw new CompletionException(ex);
155
+ }
156
+ return null;
157
+ }).whenComplete((unused, throwable) -> {
158
+ if (throwable==null){
159
+ promise.resolve(WoosmapMessageAndKey.deleteMessage);
160
+ }
161
+ else{
162
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
163
+ }
164
+ });
165
+ }
166
+
167
+ @RequiresApi(api = Build.VERSION_CODES.N)
168
+ public void enqueGetAllPoiRequest(Promise promise) {
169
+ CompletableFuture.supplyAsync(() -> {
170
+ try {
171
+ POI[] pois;
172
+ WritableArray array= Arguments.createArray();
173
+ pois = WoosmapDb.getInstance(context).getPOIsDAO().getAllPOIs();
174
+ for (POI poi : pois) {
175
+ array.pushMap(WoosmapUtil.getPOIWritableMap(poi));
176
+ }
177
+ return array;
178
+ } catch (Exception ex) {
179
+ throw new CompletionException(ex);
180
+ }
181
+ }).whenComplete((data, throwable) -> {
182
+ if (throwable == null) {
183
+ promise.resolve(data);
184
+ } else {
185
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
186
+ }
187
+ });
188
+ }
189
+ @RequiresApi(api = Build.VERSION_CODES.N)
190
+ public void enqueGetPOIRequest(String locationID,Promise promise) {
191
+ CompletableFuture.supplyAsync(() -> {
192
+ try {
193
+ POI poi;
194
+ poi = WoosmapDb.getInstance(context).getPOIsDAO().getPOIbyStoreId(locationID);
195
+ if(poi!=null){
196
+ return WoosmapUtil.getPOIWritableMap(poi);
197
+ }else {
198
+ if(WoosmapUtil.onlyContainsNumbers(locationID)){
199
+ poi = WoosmapDb.getInstance(context).getPOIsDAO().getPOIbyLocationID(Integer.parseInt(locationID));
200
+ if(poi!=null){
201
+ return WoosmapUtil.getPOIWritableMap(poi);
202
+ }
203
+ }
204
+ }
205
+ } catch (Exception ex) {
206
+ throw new CompletionException(ex);
207
+ }
208
+ return null;
209
+ }).whenComplete((data, throwable) -> {
210
+ if (throwable == null) {
211
+ if(data==null){
212
+ promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.invalidLocationid);
213
+ }else {
214
+ promise.resolve(data);
215
+ }
216
+ } else {
217
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
218
+ }
219
+ });
220
+ }
221
+ @RequiresApi(api = Build.VERSION_CODES.N)
222
+ protected void enqueueGetLocationRequest(String locationID,Promise promise) {
223
+ CompletableFuture.supplyAsync(() -> {
224
+ try {
225
+ MovingPosition requiredLocation=null;
226
+ MovingPosition[]movingPosition;
227
+ movingPosition = WoosmapDb.getInstance(context).getMovingPositionsDao().getMovingPositions(-1);
228
+ for (MovingPosition location : movingPosition) {
229
+ if(location.id==Integer.parseInt(locationID)){
230
+ requiredLocation=location;
231
+ break;
232
+ }
233
+ }
234
+ if(requiredLocation!=null){
235
+ return WoosmapUtil.getMovingPositionObject(requiredLocation);
236
+ }
237
+
238
+ } catch (Exception ex) {
239
+ throw new CompletionException(ex);
240
+ }
241
+ return null;
242
+ }).whenComplete((data, throwable) -> {
243
+ if (throwable == null) {
244
+ if(data==null){
245
+ promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.invalidLocationID);
246
+ }else {
247
+ promise.resolve(data);
248
+ }
249
+ } else {
250
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
251
+ }
252
+ });
253
+ }
254
+
255
+ @RequiresApi(api = Build.VERSION_CODES.N)
256
+ protected void enqueueGetLocationRequest(Promise promise) {
257
+ CompletableFuture.supplyAsync(() -> {
258
+ try {
259
+ MovingPosition[]movingPosition;
260
+ WritableArray array= Arguments.createArray();
261
+ movingPosition = WoosmapDb.getInstance(context).getMovingPositionsDao().getMovingPositions(-1);
262
+ for (MovingPosition location : movingPosition) {
263
+ array.pushMap(WoosmapUtil.getMovingPositionObject(location));
264
+ }
265
+ return array;
266
+ } catch (Exception ex) {
267
+ throw new CompletionException(ex);
268
+ }
269
+ }).whenComplete((data, throwable) -> {
270
+ if (throwable == null) {
271
+ promise.resolve(data);
272
+ } else {
273
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
274
+ }
275
+ });
276
+ }
277
+ @RequiresApi(api = Build.VERSION_CODES.N)
278
+ protected void removeAllLocation(final Promise promise){
279
+ CompletableFuture.supplyAsync((Supplier<Void>) () -> {
280
+ try{
281
+ WoosmapDb.getInstance(context).getMovingPositionsDao().deleteAllMovingPositions();
282
+ }
283
+ catch (Exception ex){
284
+ throw new CompletionException(ex);
285
+ }
286
+ return null;
287
+ }).whenComplete((unused, throwable) -> {
288
+ if (throwable==null){
289
+ promise.resolve(WoosmapMessageAndKey.deleteMessage);
290
+ }
291
+ else{
292
+ promise.reject(WoosmapMessageAndKey.errorCode,throwable.getMessage());
293
+ }
294
+ });
295
+ }
296
+
297
+
298
+
299
+ }
@@ -3,10 +3,14 @@ package com.reactnativeplugingeofencing;
3
3
  import android.location.Location;
4
4
  import android.util.Log;
5
5
 
6
+ import androidx.annotation.Nullable;
7
+
6
8
  import com.facebook.react.bridge.WritableArray;
7
9
  import com.facebook.react.bridge.WritableMap;
8
10
  import com.facebook.react.bridge.WritableNativeArray;
9
11
  import com.facebook.react.bridge.WritableNativeMap;
12
+ import com.webgeoservices.woosmapgeofencing.database.MovingPosition;
13
+ import com.webgeoservices.woosmapgeofencing.database.POI;
10
14
  import com.webgeoservices.woosmapgeofencing.database.Region;
11
15
  import com.webgeoservices.woosmapgeofencing.database.RegionLog;
12
16
 
@@ -71,4 +75,108 @@ public class WoosmapUtil {
71
75
  return null;
72
76
  }
73
77
 
78
+ @Nullable
79
+ protected static WritableMap getPOIWritableMap(POI poi){
80
+ WritableMap map=new WritableNativeMap();
81
+ try{
82
+ map.putDouble("date", poi.dateTime);
83
+ map.putDouble("distance", poi.distance);
84
+ map.putString("locationid", String.valueOf(poi.locationId));
85
+ map.putDouble("latitude", poi.lat);
86
+ map.putDouble("longitude", poi.lng);
87
+ map.putString("city", poi.city);
88
+ map.putString("idstore", poi.idStore);
89
+ map.putString("name", poi.name);
90
+ map.putString("duration", poi.duration);
91
+ map.putString("zipcode", poi.zipCode);
92
+ //map.putString("jsondata", poi.data);
93
+ try {
94
+ JSONObject obj = new JSONObject(poi.data);
95
+ map.putMap("jsondata", convertJsonToMap(obj));
96
+ } catch (Throwable t) {
97
+ Log.e("Geofence Plugin", "Could not parse malformed JSON: \"" + poi.data + "\"");
98
+ }
99
+
100
+ return map;
101
+ }
102
+ catch (Exception ex){
103
+ Log.e(TAG,ex.toString());
104
+ }
105
+ return null;
106
+ }
107
+
108
+ public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
109
+ WritableArray array = new WritableNativeArray();
110
+
111
+ for (int i = 0; i < jsonArray.length(); i++) {
112
+ Object value = jsonArray.get(i);
113
+ if (value instanceof JSONObject) {
114
+ array.pushMap(convertJsonToMap((JSONObject) value));
115
+ } else if (value instanceof JSONArray) {
116
+ array.pushArray(convertJsonToArray((JSONArray) value));
117
+ } else if (value instanceof Boolean) {
118
+ array.pushBoolean((Boolean) value);
119
+ } else if (value instanceof Integer) {
120
+ array.pushInt((Integer) value);
121
+ } else if (value instanceof Double) {
122
+ array.pushDouble((Double) value);
123
+ } else if (value instanceof String) {
124
+ array.pushString((String) value);
125
+ } else {
126
+ array.pushString(String.valueOf(value));
127
+ }
128
+ }
129
+ return array;
130
+ }
131
+
132
+ private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
133
+ WritableMap map = new WritableNativeMap();
134
+
135
+ Iterator<String> iterator = jsonObject.keys();
136
+ while (iterator.hasNext()) {
137
+ String key = iterator.next();
138
+ Object value = jsonObject.get(key);
139
+ if (value instanceof JSONObject) {
140
+ map.putMap(key, convertJsonToMap((JSONObject) value));
141
+ } else if (value instanceof JSONArray) {
142
+ map.putArray(key, convertJsonToArray((JSONArray) value));
143
+ } else if (value instanceof Boolean) {
144
+ map.putBoolean(key, (Boolean) value);
145
+ } else if (value instanceof Integer) {
146
+ map.putInt(key, (Integer) value);
147
+ } else if (value instanceof Double) {
148
+ map.putDouble(key, (Double) value);
149
+ } else if (value instanceof String) {
150
+ map.putString(key, (String) value);
151
+ } else {
152
+ map.putString(key, String.valueOf(value));
153
+ }
154
+ }
155
+ return map;
156
+ }
157
+ protected static WritableMap getMovingPositionObject(MovingPosition location){
158
+ try{
159
+ WritableMap map=new WritableNativeMap();
160
+ map.putDouble("latitude", location.lat);
161
+ map.putDouble("longitude", location.lng);
162
+ map.putString("locationid", String.valueOf(location.id));
163
+ map.putString("locationdescription", "description");
164
+ map.putDouble("date", location.dateTime);
165
+ return map;
166
+ }
167
+ catch (Exception ex){
168
+ Log.e(TAG,ex.toString());
169
+ }
170
+ return null;
171
+ }
172
+ protected static boolean onlyContainsNumbers(String text) {
173
+ try {
174
+ Long.parseLong(text);
175
+ return true;
176
+ } catch (NumberFormatException ex) {
177
+ return false;
178
+ }
179
+ }
180
+
181
+
74
182
  }
@@ -7,29 +7,22 @@
7
7
  import Foundation
8
8
  import CoreLocation
9
9
  import WoosmapGeofencing
10
+ import SwiftUI
10
11
 
11
12
  public class DataDistance: DistanceAPIDelegate {
12
- public func distanceAPIResponse(distance: [Distance]) {
13
-
14
- }
15
13
 
16
14
  public init() {}
17
15
 
18
- public func distanceAPIResponseData(distanceAPIData: DistanceAPIData, locationId: String) {
19
- if distanceAPIData.status == "OK" {
20
- if distanceAPIData.rows?.first?.elements?.first?.status == "OK" {
21
- let distance = distanceAPIData.rows?.first?.elements?.first?.distance
22
- let duration = distanceAPIData.rows?.first?.elements?.first?.duration
23
- if distance != nil && duration != nil {
24
- // TODO: Implementation missing
25
- //let result: DistanceResponseResult = DistanceResponseResult.init(locationId: locationId, distance: distance!, duration: duration!)
26
- //NotificationCenter.default.post(name: .distanceCalculated, object: self, userInfo: ["Distance": result])
27
- }
28
- }
29
- } else {
30
- let result: DistanceResponseError = DistanceResponseError.init(locationId: locationId, error: distanceAPIData.status ?? "-")
31
- NotificationCenter.default.post(name: .distanceCalculated, object: self, userInfo: ["Distance": result])
32
- }
16
+ public func distanceAPIResponse(distance: [Distance]) {
17
+
18
+ distance.forEach({ distanceElement in
19
+ let distance = distanceElement.distance
20
+ let duration = distanceElement.duration
21
+ let result: DistanceResponseResult = DistanceResponseResult.init(distance: distance, duration: duration)
22
+ NotificationCenter.default.post(name: .distanceCalculated, object: self, userInfo: ["Distance": result])
23
+ // print(distance?.value ?? 0)
24
+ // print(duration?.text ?? 0)
25
+ })
33
26
  }
34
27
 
35
28
  public func distanceAPIError(error: String) {
@@ -42,11 +35,9 @@ extension Notification.Name {
42
35
  }
43
36
 
44
37
  class DistanceResponseResult {
45
- var locationId: String = ""
46
- var distance: Distance
47
- var duration: Distance
48
- required init(locationId: String, distance: Distance, duration: Distance) {
49
- self.locationId = locationId
38
+ var distance: Int
39
+ var duration: Int
40
+ required init(distance: Int, duration: Int) {
50
41
  self.distance = distance
51
42
  self.duration = duration
52
43
  }
@@ -15,6 +15,18 @@ public class DataLocation: LocationServiceDelegate {
15
15
 
16
16
  public func tracingLocation(location: Location) {
17
17
  NotificationCenter.default.post(name: .newLocationSaved, object: self, userInfo: ["Location": location])
18
+
19
+ // let content = UNMutableNotificationContent()
20
+ // content.title = "Location update"
21
+ // content.body = "Location = " + "Lat = " + String(format: "%f", location.latitude) + " Lng = " + String(format: "%f", location.longitude)
22
+ // // Create the request
23
+ // let uuidString = UUID().uuidString
24
+ // let request = UNNotificationRequest(identifier: uuidString,
25
+ // content: content, trigger: nil)
26
+ //
27
+ // // Schedule the request with the system.
28
+ // let notificationCenter = UNUserNotificationCenter.current()
29
+ // notificationCenter.add(request)
18
30
  }
19
31
 
20
32
  public func tracingLocationDidFailWithError(error: Error) {
@@ -24,6 +36,10 @@ public class DataLocation: LocationServiceDelegate {
24
36
  public func readLocations() -> [Location] {
25
37
  return Locations.getAll()
26
38
  }
39
+
40
+ public func readLocations(id:String) -> Location? {
41
+ return Locations.getLocationByLocationID(locationId: id)
42
+ }
27
43
 
28
44
  public func eraseLocations() {
29
45
  Locations.deleteAll()
package/ios/DataPOI.swift CHANGED
@@ -22,6 +22,17 @@ public class DataPOI: SearchAPIDelegate {
22
22
  public func readPOI() -> [POI] {
23
23
  return POIs.getAll()
24
24
  }
25
+
26
+ public func readPOI(id: String) ->POI? {
27
+ if let poiinfo = POIs.getPOIbyIdStore(idstore: id){
28
+ return poiinfo
29
+ }
30
+ return POIs.getPOIbyLocationID(locationId: id);
31
+ }
32
+
33
+ public func readPOIByStore(id: String) ->POI? {
34
+ return POIs.getPOIbyIdStore(idstore: id);
35
+ }
25
36
 
26
37
  func getPOIbyLocationID(locationId: String) -> POI? {
27
38
  return POIs.getPOIbyLocationID(locationId: locationId)
@@ -20,12 +20,10 @@ public class DataRegion: RegionsServiceDelegate {
20
20
 
21
21
  public func didEnterPOIRegion(POIregion: Region) {
22
22
  NotificationCenter.default.post(name: .didEventPOIRegion, object: self, userInfo: ["Region": POIregion])
23
- sendNotification(POIregion: POIregion, didEnter: true)
24
23
  }
25
24
 
26
25
  public func didExitPOIRegion(POIregion: Region) {
27
26
  NotificationCenter.default.post(name: .didEventPOIRegion, object: self, userInfo: ["Region": POIregion])
28
- sendNotification(POIregion: POIregion, didEnter: false)
29
27
  }
30
28
 
31
29
  public func workZOIEnter(classifiedRegion: Region) {
@@ -35,40 +33,45 @@ public class DataRegion: RegionsServiceDelegate {
35
33
  public func homeZOIEnter(classifiedRegion: Region) {
36
34
  NotificationCenter.default.post(name: .didEventPOIRegion, object: self, userInfo: ["Region": classifiedRegion])
37
35
  }
38
-
36
+
37
+ /// Read POI Regions
38
+ /// - Returns: Region info
39
39
  public func readRegions() -> [Region] {
40
40
  return Regions.getAll()
41
41
  }
42
-
42
+
43
+ /// Read POI Regions
44
+ /// - Parameter id: Identifier
45
+ /// - Returns: Region info
46
+ public func readRegions(id:String) -> Region? {
47
+ return Regions.getRegionFromId(id: id)
48
+ }
49
+
50
+ /// Read Isochrone Regions
51
+ /// - Returns: Region info
52
+ public func readIsochroneRegions() -> [RegionIsochrone] {
53
+ return RegionIsochrones.getAll()
54
+ }
55
+
56
+ /// Read Isochrone Regions
57
+ /// - Parameter id: Identifier
58
+ /// - Returns: Region info
59
+ public func readIsochroneRegions(id:String) -> RegionIsochrone? {
60
+ return RegionIsochrones.getRegionFromId(id: id)
61
+ }
62
+
63
+ /// Erase All Regions
43
64
  public func eraseRegions() {
44
65
  Regions.deleteAll()
66
+ RegionIsochrones.deleteAll()
45
67
  }
46
-
47
- public func sendNotification(POIregion: Region, didEnter: Bool) {
48
- let content = UNMutableNotificationContent()
49
- if didEnter {
50
- content.title = "Region enter"
51
- } else {
52
- content.title = "Region exit"
53
- }
54
- content.body = "Region = " + POIregion.identifier
55
- content.body += "Lat = " + String(format: "%f", POIregion.latitude) + " Lng = " + String(format: "%f", POIregion.longitude)
56
- content.body += "\n FromPositionDetection = " + String(POIregion.fromPositionDetection)
57
- // Create the request
58
- let uuidString = UUID().uuidString
59
- let request = UNNotificationRequest(identifier: uuidString,
60
- content: content, trigger: nil)
61
-
62
- let center = UNUserNotificationCenter.current()
63
- center.getNotificationSettings { settings in
64
- if settings.authorizationStatus == .authorized {
65
- // Schedule the request with the system.
66
- let notificationCenter = UNUserNotificationCenter.current()
67
- notificationCenter.add(request)
68
- }
69
- }
70
-
68
+
69
+ /// Erase Regions by ID
70
+ /// - Parameter id: Identifier
71
+ public func eraseRegions(id:String) {
72
+ RegionIsochrones.removeRegionIsochrone(id: id)
71
73
  }
74
+
72
75
  }
73
76
 
74
77
  extension Notification.Name {
@@ -22,42 +22,42 @@ public class MarketingCloudEvents: MarketingCloudEventsDelegate {
22
22
 
23
23
  public func regionEnterEvent(regionEvent: [String: Any], eventName: String) {
24
24
  // here you can modify your event name and add your data in the dictonnary
25
- print("MarketingCloudEvents regionEnterEvent")
25
+ //print("MarketingCloudEvents regionEnterEvent")
26
26
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: regionEvent)
27
27
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
28
28
  }
29
29
 
30
30
  public func regionExitEvent(regionEvent: [String: Any], eventName: String) {
31
31
  // here you can modify your event name and add your data in the dictonnary
32
- print("MarketingCloudEvents regionExitEvent")
32
+ //print("MarketingCloudEvents regionExitEvent")
33
33
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: regionEvent)
34
34
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
35
35
  }
36
36
 
37
37
  public func visitEvent(visitEvent: [String: Any], eventName: String) {
38
38
  // here you can modify your event name and add your data in the dictonnary
39
- print("MarketingCloudEvents visitEvent")
39
+ //print("MarketingCloudEvents visitEvent")
40
40
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: visitEvent)
41
41
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
42
42
  }
43
43
 
44
44
  public func poiEvent(POIEvent: [String: Any], eventName: String) {
45
45
  // here you can modify your event name and add your data in the dictonnary
46
- print("MarketingCloudEvents poiEvent")
46
+ //print("MarketingCloudEvents poiEvent")
47
47
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: POIEvent)
48
48
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
49
49
  }
50
50
 
51
51
  public func ZOIclassifiedEnter(regionEvent: [String: Any], eventName: String) {
52
52
  // here you can modify your event name and add your data in the dictonnary
53
- print("MarketingCloudEvents ZOIclassifiedEnter")
53
+ //print("MarketingCloudEvents ZOIclassifiedEnter")
54
54
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: regionEvent)
55
55
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
56
56
  }
57
57
 
58
58
  public func ZOIclassifiedExit(regionEvent: [String: Any], eventName: String) {
59
59
  // here you can modify your event name and add your data in the dictonnary
60
- print("MarketingCloudEvents ZOIclassifiedExit")
60
+ //print("MarketingCloudEvents ZOIclassifiedExit")
61
61
  let result: MarketingData = MarketingData.init(eventname: eventName, properties: regionEvent)
62
62
  NotificationCenter.default.post(name: .marketingEvent, object: self, userInfo: ["Marketing": result])
63
63
  }