@woosmap/react-native-plugin-geofencing 0.1.3 → 0.1.6

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/README.md CHANGED
@@ -46,8 +46,6 @@ if you are using **M1 Mac** Update pod post installation like
46
46
  end
47
47
  ```
48
48
 
49
- For Android
50
- - ToDo: Please update for Android
51
49
 
52
50
  ### Supported Platforms ###
53
51
  ---
@@ -94,9 +92,10 @@ WoosmapGeofencing.getPermissionsStatus()
94
92
  ```
95
93
 
96
94
  Parameter status will be a string, one of:
97
- * `GRANTED_BACKGROUND` : User has granted location access even when app is not running in the foreground
98
- * `GRANTED_FOREGROUND` : Location access is granted only while user is using the app
99
- * `DENIED`: Location access is denied
95
+ * `GRANTED_BACKGROUND` : User has granted location access even when app is not running in the foreground.
96
+ * `GRANTED_FOREGROUND` : Location access is granted only while user is using the app.
97
+ * `DENIED`: Location access is denied.
98
+ * `UNKNOWN`: Without providing or denying any permission then it will return unknown.
100
99
 
101
100
  **_Please note_**: Plugin will not work as expected if location access is denied.
102
101
 
@@ -30,6 +30,9 @@ import java.util.ArrayList;
30
30
  import java.util.HashMap;
31
31
  import java.util.Iterator;
32
32
 
33
+ /**
34
+ * This is a React native plugin exposing Woosmap Geofencing SDK methods.
35
+ */
33
36
  @ReactModule(name = PluginGeofencingModule.NAME)
34
37
  public class PluginGeofencingModule extends ReactContextBaseJavaModule implements PermissionListener, LifecycleEventListener {
35
38
  public static final String NAME = "PluginGeofencing";
@@ -47,6 +50,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
47
50
  this.reactContext.addLifecycleEventListener(this);
48
51
  }
49
52
 
53
+ /***
54
+ * Return plugin name.
55
+ * @return woosmap native plugin name.which is constant for android and ios.
56
+ */
50
57
  @Override
51
58
  @NonNull
52
59
  public String getName() {
@@ -62,6 +69,12 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
62
69
  }
63
70
 
64
71
 
72
+ /***
73
+ * Initializes Woosmap object with given parameters.
74
+ * @param map ReadableMap may contain privateKeyWoosmapAPI with Woosmap API key,
75
+ * trackingProfile with tracking profile info.
76
+ * @param promise React native callback context.
77
+ */
65
78
  @ReactMethod
66
79
  public void initialize(ReadableMap map, Promise promise) {
67
80
  String trackingProfile = "";
@@ -106,6 +119,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
106
119
 
107
120
  }
108
121
 
122
+ /***
123
+ * Checks if Woosmap object is instantiated.
124
+ * @return true if woosmap sdk is initialized else false.
125
+ */
109
126
  private boolean isWoosmapInitialized() {
110
127
  if (woosmap == null) {
111
128
  return false;
@@ -113,6 +130,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
113
130
  return true;
114
131
  }
115
132
 
133
+ /***
134
+ * Requests permissions. If the background permission is required then ACCESS_BACKGROUND_LOCATION is requested for devices above Android 9.
135
+ * @param data Readable Array containing a boolean parameter to check if the background permission is required.
136
+ */
116
137
  @ReactMethod
117
138
  private void requestPermissions(ReadableArray data, Promise promise) {
118
139
  try {
@@ -146,6 +167,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
146
167
  return true;
147
168
  }
148
169
 
170
+ /***
171
+ * Provide status of foreground and background location permission.
172
+ * @param promise React native callback context.
173
+ */
149
174
  private void providePermissionStatus(final Promise promise) {
150
175
  try {
151
176
  if (promise == null) {
@@ -179,11 +204,23 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
179
204
  }
180
205
  }
181
206
 
207
+ /***
208
+ * Checks if the required location permissions are granted or not.
209
+ * Returns DENIED if no permissions are granted.
210
+ * Returns GRANTED_FOREGROUND if foreground location permission is granted.
211
+ * Returns GRANTED_BACKGROUND if background location permission is granted.
212
+ * Returns UNKNOWN if plugin is unable to determine or asking for permission without providing any permission.
213
+ */
182
214
  @ReactMethod
183
215
  public void getPermissionsStatus(final Promise promise) {
184
216
  providePermissionStatus(promise);
185
217
  }
186
218
 
219
+ /***
220
+ * Check if the user has given location permission.
221
+ * @param isBackground Pass true if the background permission needs to be checked.
222
+ * @return boolean
223
+ */
187
224
  private boolean hasPermission(boolean isBackground) {
188
225
  try {
189
226
  Activity activity = getCurrentActivity();
@@ -225,6 +262,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
225
262
  }
226
263
  }
227
264
 
265
+ /***
266
+ * Sets the Woosmap private API key for calling Woosmap APIs.
267
+ * @param data accepts Woosmap API key in a Readable array.
268
+ * @param promise React native callback context.
269
+ */
228
270
  @ReactMethod
229
271
  public void setWoosmapApiKey(ReadableArray data, Promise promise) {
230
272
  try {
@@ -248,6 +290,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
248
290
  }
249
291
  }
250
292
 
293
+ /***
294
+ * Starts Woosmap Geofencing tracking.
295
+ * @param data Accepts tracking profile. Value can be either liveTracking, passiveTracking or stopsTracking.
296
+ * @param promise React native callback context.
297
+ */
251
298
  @ReactMethod
252
299
  public void startTracking(ReadableArray data, Promise promise) {
253
300
  try {
@@ -273,6 +320,10 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
273
320
  }
274
321
  }
275
322
 
323
+ /***
324
+ * Stops tracking
325
+ * @param promise React native callback context.
326
+ */
276
327
  @ReactMethod
277
328
  public void stopTracking(Promise promise) {
278
329
  try {
@@ -288,6 +339,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
288
339
  }
289
340
  }
290
341
 
342
+ /***
343
+ * Add watch to woosmap location data.
344
+ * @param watchID Unique String value for location listener.
345
+ * @param promise React native callback context.
346
+ */
291
347
  @ReactMethod
292
348
  public void watchLocation(String watchID, Promise promise) {
293
349
  try {
@@ -307,6 +363,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
307
363
  }
308
364
  }
309
365
 
366
+ /***
367
+ * Clear woosmap location watch.
368
+ * @param watchID Unique String value for location listener.
369
+ * @param promise React native callback context.
370
+ */
310
371
  @ReactMethod
311
372
  public void clearLocationWatch(String watchID, Promise promise) {
312
373
  try {
@@ -322,6 +383,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
322
383
  }
323
384
  }
324
385
 
386
+ /***
387
+ * Sets Sales Force Marketing Cloud credentials.
388
+ * @param map accepts Sales Force Marketing Cloud credentials key in a ReadableMap.
389
+ * @param promise React native callback context.
390
+ */
325
391
  @ReactMethod
326
392
  private void setSFMCCredentials(ReadableMap map, Promise promise) {
327
393
  try {
@@ -365,6 +431,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
365
431
  }
366
432
  }
367
433
 
434
+ /***
435
+ * Add watch to woosmap region data.
436
+ * @param watchID Unique String value for region listener.
437
+ * @param promise React native callback context.
438
+ */
368
439
  @ReactMethod
369
440
  public void watchRegions(String watchID, Promise promise) {
370
441
  try {
@@ -385,6 +456,12 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
385
456
  }
386
457
  }
387
458
 
459
+ /***
460
+ * Clear woosmap region watch.
461
+ * @param watchID Unique String value for region listener.Which is getting
462
+ * @param promise React native callback context.
463
+ */
464
+
388
465
  @ReactMethod
389
466
  public void clearRegionsWatch(String watchID, Promise promise) {
390
467
  try {
@@ -401,35 +478,39 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
401
478
  }
402
479
  }
403
480
 
481
+ /***
482
+ * Set radius of POI
483
+ * @param radius A string containing POI radius value in number,string,double format.
484
+ * @param promise React native callback context.
485
+ */
404
486
  @ReactMethod
405
- public void setPoiRadius(String radius,Promise promise){
406
- try{
407
- if (isWoosmapInitialized()){
408
- if (radius.isEmpty()){
487
+ public void setPoiRadius(String radius, Promise promise) {
488
+ try {
489
+ if (isWoosmapInitialized()) {
490
+ if (radius.isEmpty()) {
409
491
  throw new Exception(WoosmapMessageAndKey.radiusEmptyMessage);
410
492
  }
411
- if(onlyContainsNumbers(radius)){
412
- WoosmapSettings.poiRadius=Integer.parseInt(radius);
493
+ if (onlyContainsNumbers(radius)) {
494
+ WoosmapSettings.poiRadius = Integer.parseInt(radius);
413
495
  promise.resolve(WoosmapMessageAndKey.successMessage);
414
- }else if(onlyContainsDouble(radius)){
415
- double d=Double.parseDouble(radius);
416
- WoosmapSettings.poiRadius=(int) Math.round(d);
496
+ } else if (onlyContainsDouble(radius)) {
497
+ double d = Double.parseDouble(radius);
498
+ WoosmapSettings.poiRadius = (int) Math.round(d);
417
499
  promise.resolve(WoosmapMessageAndKey.successMessage);
418
- }else {
419
- WoosmapSettings.poiRadiusNameFromResponse=radius;
500
+ } else {
501
+ WoosmapSettings.poiRadiusNameFromResponse = radius;
420
502
  promise.resolve(WoosmapMessageAndKey.successMessage);
421
503
  }
422
- }else {
504
+ } else {
423
505
  promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
424
506
  }
425
- }
426
- catch (Exception ex){
427
- promise.reject(WoosmapMessageAndKey.errorCode,ex.getMessage());
507
+ } catch (Exception ex) {
508
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
428
509
  }
429
510
  }
430
511
 
431
- /**
432
- *
512
+ /***
513
+ * Its check string is integer or not.
433
514
  * @param text string for checking if it contains only number or not.
434
515
  * @return true boolean value if string is only number else false.
435
516
  */
@@ -442,6 +523,11 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
442
523
  }
443
524
  }
444
525
 
526
+ /***
527
+ * Its check string is double or not.
528
+ * @param text String for checking if it contain double or not.
529
+ * @return true boolean value if string is double else false.
530
+ */
445
531
  private boolean onlyContainsDouble(String text) {
446
532
  try {
447
533
  Double.parseDouble(text);
@@ -450,6 +536,6 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
450
536
  return false;
451
537
  }
452
538
  }
453
-
539
+
454
540
 
455
541
  }
@@ -10,6 +10,9 @@ import com.facebook.react.bridge.ReactContext;
10
10
  import com.facebook.react.modules.core.DeviceEventManagerModule;
11
11
  import com.webgeoservices.woosmapgeofencing.Woosmap;
12
12
 
13
+ /***
14
+ * Implements Woosmap Location Ready callbacks
15
+ */
13
16
  public class WoosLocationReadyListener implements Woosmap.LocationReadyListener {
14
17
  private ReactNativeHost reactNativeHost;
15
18
  private Context context;
@@ -11,6 +11,9 @@ import com.webgeoservices.woosmapgeofencing.Woosmap;
11
11
  import com.webgeoservices.woosmapgeofencing.database.Region;
12
12
  import com.webgeoservices.woosmapgeofencing.database.RegionLog;
13
13
 
14
+ /***
15
+ * Implements Woosmap Region callbacks
16
+ */
14
17
  public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woosmap.RegionLogReadyListener {
15
18
 
16
19
  private ReactNativeHost reactNativeHost;
@@ -1,5 +1,6 @@
1
1
  package com.reactnativeplugingeofencing;
2
2
 
3
+
3
4
  public class WoosmapMessageAndKey {
4
5
  protected static String errorCode = "1001";
5
6
  protected static String successMessage="OK";
@@ -9,9 +10,9 @@ public class WoosmapMessageAndKey {
9
10
  protected static String permissionNotGrantedMessage="Required permissions not granted";
10
11
  protected static String permissionValueNotProvided="Permission value not provided";
11
12
  protected static String unknownMessage="UNKNOWN";
12
- protected static String deniedPermissionMessage="PERMISSION_STATUS_DENIED";
13
- protected static String foregroundPermissionGrantedMessage="PERMISSION_STATUS_GRANTED_FOREGROUND";
14
- protected static String backgroundPermissionGrantedMessage="PERMISSION_STATUS_GRANTED_BACKGROUND";
13
+ protected static String deniedPermissionMessage="DENIED";
14
+ protected static String foregroundPermissionGrantedMessage="GRANTED_FOREGROUND";
15
+ protected static String backgroundPermissionGrantedMessage="GRANTED_BACKGROUND";
15
16
  protected static String woosmapKeyNotProvide="Woosmap API Key not provided";
16
17
  protected static String woosmapNotInitialized="Woosmap not initialized";
17
18
  protected static String trackingProfileNotProvided="Tracking profile is missing";
@@ -16,6 +16,9 @@ import org.json.JSONObject;
16
16
 
17
17
  import java.util.Iterator;
18
18
 
19
+ /***
20
+ * Contains misc. utility functions.
21
+ */
19
22
  public class WoosmapUtil {
20
23
  private static final String TAG="WoosmapUtil";
21
24
 
@@ -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) {
@@ -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) {
@@ -44,31 +42,6 @@ public class DataRegion: RegionsServiceDelegate {
44
42
  Regions.deleteAll()
45
43
  }
46
44
 
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
-
71
- }
72
45
  }
73
46
 
74
47
  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
  }
@@ -613,10 +613,9 @@ class PluginGeofencing: RCTEventEmitter {
613
613
 
614
614
  private func formatDistanceData(woosdata: DistanceResponseResult) -> [AnyHashable: Any] {
615
615
  var result: [AnyHashable: Any] = [:]
616
- result["locationid"] = woosdata.locationId
617
- //TODO: format it
618
- result["distance"] = "" //woosdata.distance.text
619
- result["duration"] = "" //woosdata.duration.text
616
+ result["locationid"] = ""//woosdata.locationId
617
+ result["distance"] = String(woosdata.distance)
618
+ result["duration"] = String(woosdata.duration)
620
619
  return result
621
620
  }
622
621
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/react-native-plugin-geofencing",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "This react-native plugin extends the functionality offered by the Woosmap Geofencing Mobile SDKs. Find more about the Woosmap Geofencing SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",