@woosmap/react-native-plugin-geofencing 0.1.2

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +340 -0
  3. package/android/.gradle/7.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/7.1.1/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/7.1.1/executionHistory/executionHistory.lock +0 -0
  6. package/android/.gradle/7.1.1/fileChanges/last-build.bin +0 -0
  7. package/android/.gradle/7.1.1/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/7.1.1/gc.properties +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  11. package/android/.gradle/checksums/checksums.lock +0 -0
  12. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  13. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  14. package/android/.gradle/vcs-1/gc.properties +0 -0
  15. package/android/build.gradle +60 -0
  16. package/android/src/main/AndroidManifest.xml +4 -0
  17. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +365 -0
  18. package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingPackage.java +28 -0
  19. package/android/src/main/java/com/reactnativeplugingeofencing/WoosLocationReadyListener.java +38 -0
  20. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +36 -0
  21. package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +34 -0
  22. package/ios/AirshipEvents.swift +73 -0
  23. package/ios/DataDistance.swift +61 -0
  24. package/ios/DataLocation.swift +36 -0
  25. package/ios/DataPOI.swift +38 -0
  26. package/ios/DataRegion.swift +78 -0
  27. package/ios/DataVisit.swift +30 -0
  28. package/ios/DataZOI.swift +22 -0
  29. package/ios/MarketingCloudEvents.swift +64 -0
  30. package/ios/MockDataVisit.swift +167 -0
  31. package/ios/PluginGeofencing-Bridging-Header.h +3 -0
  32. package/ios/PluginGeofencing.m +62 -0
  33. package/ios/PluginGeofencing.swift +688 -0
  34. package/ios/PluginGeofencing.xcodeproj/project.pbxproj +293 -0
  35. package/ios/WoosmapGeofenceMessage.swift +40 -0
  36. package/ios/WoosmapGeofenceService.swift +474 -0
  37. package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  38. package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  39. package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcuserdata/saturn.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  40. package/ios/WoosmapGeofencingPlugin.xcodeproj/xcuserdata/saturn.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  41. package/lib/commonjs/Airship.js +35 -0
  42. package/lib/commonjs/Airship.js.map +1 -0
  43. package/lib/commonjs/Location.js +54 -0
  44. package/lib/commonjs/Location.js.map +1 -0
  45. package/lib/commonjs/MarketingCloud.js +35 -0
  46. package/lib/commonjs/MarketingCloud.js.map +1 -0
  47. package/lib/commonjs/Poi.js +96 -0
  48. package/lib/commonjs/Poi.js.map +1 -0
  49. package/lib/commonjs/Region.js +62 -0
  50. package/lib/commonjs/Region.js.map +1 -0
  51. package/lib/commonjs/Visit.js +50 -0
  52. package/lib/commonjs/Visit.js.map +1 -0
  53. package/lib/commonjs/Zoi.js +97 -0
  54. package/lib/commonjs/Zoi.js.map +1 -0
  55. package/lib/commonjs/index.js +276 -0
  56. package/lib/commonjs/index.js.map +1 -0
  57. package/lib/module/Airship.js +33 -0
  58. package/lib/module/Airship.js.map +1 -0
  59. package/lib/module/Location.js +46 -0
  60. package/lib/module/Location.js.map +1 -0
  61. package/lib/module/MarketingCloud.js +33 -0
  62. package/lib/module/MarketingCloud.js.map +1 -0
  63. package/lib/module/Poi.js +94 -0
  64. package/lib/module/Poi.js.map +1 -0
  65. package/lib/module/Region.js +54 -0
  66. package/lib/module/Region.js.map +1 -0
  67. package/lib/module/Visit.js +48 -0
  68. package/lib/module/Visit.js.map +1 -0
  69. package/lib/module/Zoi.js +95 -0
  70. package/lib/module/Zoi.js.map +1 -0
  71. package/lib/module/index.js +261 -0
  72. package/lib/module/index.js.map +1 -0
  73. package/lib/typescript/Airship.d.ts +18 -0
  74. package/lib/typescript/Location.d.ts +26 -0
  75. package/lib/typescript/MarketingCloud.d.ts +18 -0
  76. package/lib/typescript/Poi.d.ts +48 -0
  77. package/lib/typescript/Region.d.ts +30 -0
  78. package/lib/typescript/Visit.d.ts +25 -0
  79. package/lib/typescript/Zoi.d.ts +49 -0
  80. package/lib/typescript/index.d.ts +97 -0
  81. package/package.json +150 -0
  82. package/react-native-plugin-geofencing.podspec +20 -0
  83. package/src/Airship.tsx +24 -0
  84. package/src/Location.tsx +46 -0
  85. package/src/MarketingCloud.tsx +24 -0
  86. package/src/Poi.tsx +106 -0
  87. package/src/Region.tsx +56 -0
  88. package/src/Visit.tsx +49 -0
  89. package/src/Zoi.tsx +107 -0
  90. package/src/index.tsx +255 -0
@@ -0,0 +1,365 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.Manifest;
4
+ import android.app.Activity;
5
+ import android.content.pm.PackageManager;
6
+ import android.os.Build;
7
+ import android.util.ArraySet;
8
+ import android.util.Log;
9
+
10
+ import androidx.annotation.NonNull;
11
+ import androidx.core.app.ActivityCompat;
12
+
13
+ import com.facebook.react.bridge.Callback;
14
+ import com.facebook.react.bridge.LifecycleEventListener;
15
+ import com.facebook.react.bridge.Promise;
16
+ import com.facebook.react.bridge.ReactApplicationContext;
17
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
+ import com.facebook.react.bridge.ReactMethod;
19
+ import com.facebook.react.bridge.ReadableArray;
20
+ import com.facebook.react.bridge.ReadableMap;
21
+ import com.facebook.react.bridge.WritableMap;
22
+ import com.facebook.react.module.annotations.ReactModule;
23
+ import com.facebook.react.modules.core.PermissionAwareActivity;
24
+ import com.facebook.react.modules.core.PermissionListener;
25
+ import com.webgeoservices.woosmapgeofencing.Woosmap;
26
+ import com.webgeoservices.woosmapgeofencing.WoosmapSettings;
27
+
28
+ import java.lang.reflect.Array;
29
+ import java.util.ArrayList;
30
+ import java.util.HashMap;
31
+ import java.util.Iterator;
32
+
33
+ @ReactModule(name = PluginGeofencingModule.NAME)
34
+ public class PluginGeofencingModule extends ReactContextBaseJavaModule implements PermissionListener, LifecycleEventListener {
35
+ public static final String NAME = "PluginGeofencing";
36
+
37
+ private ReactApplicationContext reactContext;
38
+ private Woosmap woosmap;
39
+ private static final int PERMISSIONS_REQUEST_CODE = 150; // random request code
40
+ private Promise mPermissionsRequestPromise;
41
+ private WoosLocationReadyListener locationReadyListener;
42
+
43
+ public PluginGeofencingModule(ReactApplicationContext reactContext) {
44
+ super(reactContext);
45
+ this.reactContext = reactContext;
46
+ this.reactContext.addLifecycleEventListener(this);
47
+ }
48
+
49
+ @Override
50
+ @NonNull
51
+ public String getName() {
52
+ return NAME;
53
+ }
54
+
55
+
56
+ // Example method
57
+ // See https://reactnative.dev/docs/native-modules-android
58
+ @ReactMethod
59
+ public void multiply(int a, int b, Promise promise) {
60
+ promise.resolve(a * b);
61
+ }
62
+
63
+
64
+ @ReactMethod
65
+ public void initialize(ReadableMap map, Promise promise) {
66
+ String trackingProfile = "";
67
+ try {
68
+ if (woosmap != null) {
69
+ promise.resolve(WoosmapMessageAndKey.successMessage);
70
+ return;
71
+ } else if (hasPermission(false)) {
72
+ //check required permission first
73
+ if (map.hasKey(WoosmapMessageAndKey.profileTrackingKey)) {
74
+ if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.liveTracking)) {
75
+ trackingProfile = Woosmap.ConfigurationProfile.liveTracking;
76
+ } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.passiveTracking)) {
77
+ trackingProfile = Woosmap.ConfigurationProfile.passiveTracking;
78
+ } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.visitsTracking)) {
79
+ trackingProfile = Woosmap.ConfigurationProfile.visitsTracking;
80
+ } else {
81
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
82
+ return;
83
+ }
84
+ }
85
+ woosmap = Woosmap.getInstance().initializeWoosmap(reactContext);
86
+ if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
87
+ WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
88
+ }
89
+ // Set the Delay of Duration data
90
+ WoosmapSettings.numberOfDayDataDuration = 30;
91
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
92
+ this.woosmap.createWoosmapNotifChannel();
93
+ }
94
+ this.woosmap.onResume();
95
+ if (!trackingProfile.isEmpty()) {
96
+ woosmap.startTracking(trackingProfile);
97
+ }
98
+ promise.resolve(WoosmapMessageAndKey.successMessage);
99
+ } else {
100
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
101
+ }
102
+ } catch (Exception ex) {
103
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
104
+ }
105
+
106
+ }
107
+
108
+ private boolean isWoosmapInitialized() {
109
+ if (woosmap == null) {
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+
115
+ @ReactMethod
116
+ private void requestPermissions(ReadableArray data, Promise promise) {
117
+ try {
118
+ if (data.isNull(0)) {
119
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionValueNotProvided);
120
+ }
121
+ boolean isBackground = data.getBoolean(0);
122
+ PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
123
+ mPermissionsRequestPromise = promise;
124
+ if (activity != null) {
125
+ if (Build.VERSION.SDK_INT >= 23) {
126
+ if (isBackground && Build.VERSION.SDK_INT >= 29) {
127
+ activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
128
+ } else {
129
+ activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
130
+ }
131
+ }
132
+ }
133
+ } catch (Exception ex) {
134
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
135
+ }
136
+ }
137
+
138
+
139
+ @Override
140
+ public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
141
+ if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
142
+ providePermissionStatus(mPermissionsRequestPromise);
143
+ mPermissionsRequestPromise = null;
144
+ }
145
+ return true;
146
+ }
147
+
148
+ private void providePermissionStatus(final Promise promise) {
149
+ try {
150
+ if (promise == null) {
151
+ return;
152
+ }
153
+ Activity activity = getCurrentActivity();
154
+ if (activity == null) {
155
+ promise.resolve(WoosmapMessageAndKey.unknownMessage);
156
+ return;
157
+ }
158
+
159
+ boolean foreground = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
160
+ boolean background = foreground;
161
+ boolean denied = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
162
+
163
+ if (Build.VERSION.SDK_INT >= 29) {
164
+ background = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
165
+ }
166
+
167
+ if (background) {
168
+ promise.resolve(WoosmapMessageAndKey.backgroundPermissionGrantedMessage);
169
+ } else if (foreground) {
170
+ promise.resolve(WoosmapMessageAndKey.foregroundPermissionGrantedMessage);
171
+ } else if (denied) {
172
+ promise.resolve(WoosmapMessageAndKey.deniedPermissionMessage);
173
+ } else {
174
+ promise.resolve(WoosmapMessageAndKey.unknownMessage);
175
+ }
176
+ } catch (Exception ex) {
177
+ promise.resolve(WoosmapMessageAndKey.unknownMessage);
178
+ }
179
+ }
180
+
181
+ @ReactMethod
182
+ public void getPermissionsStatus(final Promise promise) {
183
+ providePermissionStatus(promise);
184
+ }
185
+
186
+ private boolean hasPermission(boolean isBackground) {
187
+ try {
188
+ Activity activity = getCurrentActivity();
189
+ if (activity == null) {
190
+ return false;
191
+ }
192
+ if (!isBackground) {
193
+ return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
194
+ }
195
+ if (isBackground && Build.VERSION.SDK_INT >= 29) {
196
+ return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
197
+ }
198
+
199
+ } catch (Exception ex) {
200
+ Log.e(NAME, ex.toString());
201
+ }
202
+ return false;
203
+ }
204
+
205
+
206
+ @Override
207
+ public void onHostResume() {
208
+ if (woosmap != null) {
209
+ woosmap.onResume();
210
+ }
211
+ }
212
+
213
+ @Override
214
+ public void onHostPause() {
215
+ if (woosmap != null) {
216
+ woosmap.onPause();
217
+ }
218
+ }
219
+
220
+ @Override
221
+ public void onHostDestroy() {
222
+ if (woosmap != null) {
223
+ woosmap.onDestroy();
224
+ }
225
+ }
226
+ @ReactMethod
227
+ public void setWoosmapApiKey(ReadableArray data, Promise promise) {
228
+ try {
229
+ if (isWoosmapInitialized()) {
230
+ String apiKey = "";
231
+ if (!data.isNull(0)) {
232
+ apiKey = data.getString(0);
233
+ }
234
+ if (!apiKey.isEmpty()) {
235
+ WoosmapSettings.privateKeyWoosmapAPI = apiKey;
236
+ promise.resolve(WoosmapMessageAndKey.successMessage);
237
+ } else {
238
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
239
+ }
240
+ } else {
241
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
242
+ }
243
+
244
+ } catch (Exception ex) {
245
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
246
+ }
247
+ }
248
+
249
+ @ReactMethod
250
+ public void startTracking(ReadableArray data, Promise promise) {
251
+ try {
252
+ if (isWoosmapInitialized()) {
253
+ if (data.isNull(0)) {
254
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.trackingProfileNotProvided);
255
+ }
256
+
257
+ String trackingProfile = data.getString(0);
258
+ if (trackingProfile.equals(Woosmap.ConfigurationProfile.liveTracking) ||
259
+ trackingProfile.equals(Woosmap.ConfigurationProfile.passiveTracking) ||
260
+ trackingProfile.equals(Woosmap.ConfigurationProfile.visitsTracking)) {
261
+ woosmap.startTracking(trackingProfile);
262
+ promise.resolve(WoosmapMessageAndKey.successMessage);
263
+ } else {
264
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
265
+ }
266
+ } else {
267
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
268
+ }
269
+ } catch (Exception ex) {
270
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
271
+ }
272
+ }
273
+
274
+ @ReactMethod
275
+ public void stopTracking(Promise promise) {
276
+ try {
277
+ if (isWoosmapInitialized()) {
278
+ woosmap.stopTracking();
279
+ promise.resolve(WoosmapMessageAndKey.successMessage);
280
+ } else {
281
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
282
+ }
283
+
284
+ } catch (Exception ex) {
285
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
286
+ }
287
+ }
288
+ @ReactMethod
289
+ public void watchLocation(String watchID,Promise promise){
290
+ try {
291
+ if(isWoosmapInitialized()){
292
+ if(locationReadyListener==null){
293
+ locationReadyListener=new WoosLocationReadyListener(reactContext);
294
+ woosmap.setLocationReadyListener(locationReadyListener);
295
+ promise.resolve(watchID);
296
+ }else {
297
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchAlreadyStarted);
298
+ }
299
+ }else {
300
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
301
+ }
302
+ }catch (Exception ex){
303
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
304
+ }
305
+ }
306
+ @ReactMethod
307
+ public void clearLocationWatch(String watchID,Promise promise){
308
+ try {
309
+ if(locationReadyListener!=null){
310
+ woosmap.setLocationReadyListener(null);
311
+ locationReadyListener=null;
312
+ promise.resolve(watchID);
313
+ }else {
314
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchNotStarted);
315
+ }
316
+ }catch (Exception ex){
317
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
318
+ }
319
+ }
320
+ @ReactMethod
321
+ private void setSFMCCredentials(ReadableMap map, Promise promise){
322
+ try{
323
+ if(isWoosmapInitialized()){
324
+ if (!map.toHashMap().isEmpty()){
325
+ HashMap<String, String> SFMCInfo = new HashMap<>();
326
+ String key;
327
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCauthenticationBaseURIkey)){
328
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCauthenticationBaseURIkey);
329
+ }
330
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCrestBaseURIkey)){
331
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCrestBaseURIkey);
332
+ }
333
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_idkey)){
334
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCclient_idkey );
335
+ }
336
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_secretkey)){
337
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCclient_secretkey );
338
+ }
339
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCcontactKey)){
340
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCcontactKey );
341
+ }
342
+
343
+ Iterator<String> keys = map.toHashMap().keySet().iterator();
344
+
345
+ while (keys.hasNext()){
346
+ key = keys.next();
347
+ SFMCInfo.put(key,map.getString(key));
348
+ }
349
+ WoosmapSettings.SFMCCredentials = SFMCInfo;
350
+ promise.resolve(WoosmapMessageAndKey.successMessage);
351
+ }
352
+ else{
353
+ promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.credentialEmptyMessage);
354
+ }
355
+ }else {
356
+ promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.woosmapNotInitialized);
357
+ }
358
+
359
+ }
360
+ catch (Exception ex){
361
+ promise.reject(WoosmapMessageAndKey.errorCode,ex.getMessage());
362
+ }
363
+ }
364
+
365
+ }
@@ -0,0 +1,28 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.ReactPackage;
6
+ import com.facebook.react.bridge.NativeModule;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.uimanager.ViewManager;
9
+
10
+ import java.util.ArrayList;
11
+ import java.util.Collections;
12
+ import java.util.List;
13
+
14
+ public class PluginGeofencingPackage implements ReactPackage {
15
+ @NonNull
16
+ @Override
17
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
+ List<NativeModule> modules = new ArrayList<>();
19
+ modules.add(new PluginGeofencingModule(reactContext));
20
+ return modules;
21
+ }
22
+
23
+ @NonNull
24
+ @Override
25
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26
+ return Collections.emptyList();
27
+ }
28
+ }
@@ -0,0 +1,38 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.content.Context;
4
+ import android.location.Location;
5
+
6
+ import com.facebook.react.ReactApplication;
7
+ import com.facebook.react.ReactInstanceManager;
8
+ import com.facebook.react.ReactNativeHost;
9
+ import com.facebook.react.bridge.ReactContext;
10
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
11
+ import com.webgeoservices.woosmapgeofencing.Woosmap;
12
+
13
+ public class WoosLocationReadyListener implements Woosmap.LocationReadyListener {
14
+ private ReactNativeHost reactNativeHost;
15
+ private Context context;
16
+ public WoosLocationReadyListener(Context context){
17
+ this.context=context;
18
+ }
19
+
20
+ private void sendEvent(final String eventName, final Object data) {
21
+ final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
22
+ ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
23
+ if (reactContext != null) {
24
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
25
+ }
26
+ }
27
+ @Override
28
+ public void LocationReadyCallback(Location location) {
29
+ try {
30
+ ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
31
+ reactNativeHost = reactApplication.getReactNativeHost();
32
+ sendEvent(WoosmapMessageAndKey.locationSuccessCallbackName, WoosmapUtil.getLocationWritableMap(location));
33
+ }catch (Exception ex){
34
+ sendEvent(WoosmapMessageAndKey.locationErrorCallbackName, ex.getMessage());
35
+ }
36
+
37
+ }
38
+ }
@@ -0,0 +1,36 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ public class WoosmapMessageAndKey {
4
+ protected static String errorCode = "1001";
5
+ protected static String successMessage="OK";
6
+ protected static String profileTrackingKey="trackingProfile";
7
+ protected static String woosmapPrivateKeyString="privateKeyWoosmapAPI";
8
+ protected static String invalidProfileTrackingError="Invalid tracking profile. Only possible values are liveTracking, passiveTracking, visitsTracking";
9
+ protected static String permissionNotGrantedMessage="Required permissions not granted";
10
+ protected static String permissionValueNotProvided="Permission value not provided";
11
+ 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";
15
+ protected static String woosmapKeyNotProvide="Woosmap API Key not provided";
16
+ protected static String woosmapNotInitialized="Woosmap not initialized";
17
+ protected static String trackingProfileNotProvided="Tracking profile is missing";
18
+ protected static String locationSuccessCallbackName="geolocationDidChange";
19
+ protected static String locationErrorCallbackName="geolocationError";
20
+ protected static String locationWatchNotStarted="Location watch not started";
21
+ protected static String locationWatchAlreadyStarted="Location watch already added";
22
+ protected static String keyMissingMessage="Required key missing";
23
+ protected static String SMFCauthenticationBaseURIkey="authenticationBaseURI";
24
+ protected static String SMFCrestBaseURIkey="restBaseURI";
25
+ protected static String SMFCclient_idkey="client_id";
26
+ protected static String SMFCclient_secretkey="client_secret";
27
+ protected static String SMFCcontactKey="contactKey";
28
+ protected static String credentialEmptyMessage="Credentials cannot be empty.";
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ }
@@ -0,0 +1,34 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.location.Location;
4
+ import android.util.Log;
5
+
6
+ import com.facebook.react.bridge.WritableArray;
7
+ import com.facebook.react.bridge.WritableMap;
8
+ import com.facebook.react.bridge.WritableNativeArray;
9
+ import com.facebook.react.bridge.WritableNativeMap;
10
+
11
+ import org.json.JSONArray;
12
+ import org.json.JSONException;
13
+ import org.json.JSONObject;
14
+
15
+ import java.util.Iterator;
16
+
17
+ public class WoosmapUtil {
18
+ private static final String TAG="WoosmapUtil";
19
+
20
+ protected static WritableMap getLocationWritableMap(Location location){
21
+ WritableMap map=new WritableNativeMap();
22
+ try {
23
+ map.putDouble("latitude", location.getLatitude());
24
+ map.putDouble("longitude", location.getLongitude());
25
+ map.putString("locationid", "1");
26
+ map.putString("locationdescription", "description");
27
+ map.putDouble("date", location.getTime());
28
+ }catch (Exception ex){
29
+ Log.e(TAG,ex.toString());
30
+ }
31
+ return map;
32
+ }
33
+
34
+ }
@@ -0,0 +1,73 @@
1
+ //
2
+ // AirshipEvents.swift
3
+ // Sample
4
+ //
5
+ //
6
+
7
+ import Foundation
8
+ import CoreLocation
9
+ import WoosmapGeofencing
10
+ #if canImport(AirshipCore)
11
+ import AirshipCore
12
+ #endif
13
+
14
+ class AirshipData {
15
+ var eventname: String = ""
16
+ var properties: [String: Any]
17
+
18
+ required init(eventname: String, properties: [String: Any]) {
19
+ self.eventname = eventname
20
+ self.properties = properties
21
+ }
22
+ }
23
+
24
+ public class AirshipEvents: AirshipEventsDelegate {
25
+
26
+ public init() {}
27
+
28
+ public func regionEnterEvent(regionEvent: [String: Any], eventName: String) {
29
+ #if canImport(AirshipCore)
30
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
31
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
32
+ #endif
33
+ }
34
+
35
+ public func regionExitEvent(regionEvent: [String: Any], eventName: String) {
36
+ #if canImport(AirshipCore)
37
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
38
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
39
+ #endif
40
+ }
41
+
42
+ public func visitEvent(visitEvent: [String: Any], eventName: String) {
43
+ #if canImport(AirshipCore)
44
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
45
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
46
+ #endif
47
+ }
48
+
49
+ public func poiEvent(POIEvent: [String: Any], eventName: String) {
50
+ #if canImport(AirshipCore)
51
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
52
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
53
+ #endif
54
+ }
55
+
56
+ public func ZOIclassifiedEnter(regionEvent: [String: Any], eventName: String) {
57
+ #if canImport(AirshipCore)
58
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
59
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
60
+ #endif
61
+ }
62
+
63
+ public func ZOIclassifiedExit(regionEvent: [String: Any], eventName: String) {
64
+ #if canImport(AirshipCore)
65
+ var result: AirshipData = AirshipData.init(eventname: eventName, properties: regionEvent)
66
+ NotificationCenter.default.post(name: .airshipEvent, object: self, userInfo: ["Airship": result])
67
+ #endif
68
+ }
69
+ }
70
+
71
+ extension Notification.Name {
72
+ static let airshipEvent = Notification.Name("airshipEvent")
73
+ }
@@ -0,0 +1,61 @@
1
+ //
2
+ // DataDistance.swift
3
+ // Sample
4
+ //
5
+ //
6
+
7
+ import Foundation
8
+ import CoreLocation
9
+ import WoosmapGeofencing
10
+
11
+ public class DataDistance: DistanceAPIDelegate {
12
+ public func distanceAPIResponse(distance: [Distance]) {
13
+
14
+ }
15
+
16
+ public init() {}
17
+
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
+ }
33
+ }
34
+
35
+ public func distanceAPIError(error: String) {
36
+ print(error)
37
+ }
38
+
39
+ }
40
+ extension Notification.Name {
41
+ static let distanceCalculated = Notification.Name("POIDistanceCalculated")
42
+ }
43
+
44
+ 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
50
+ self.distance = distance
51
+ self.duration = duration
52
+ }
53
+ }
54
+ class DistanceResponseError {
55
+ var locationId: String = ""
56
+ var error: String
57
+ required init(locationId: String, error: String ) {
58
+ self.locationId = locationId
59
+ self.error = error
60
+ }
61
+ }
@@ -0,0 +1,36 @@
1
+ //
2
+ // DataLocation.swift
3
+ // WoosmapGeofencing
4
+ //
5
+ //
6
+
7
+ import Foundation
8
+ import UIKit
9
+ import CoreLocation
10
+ import WoosmapGeofencing
11
+
12
+ public class DataLocation: LocationServiceDelegate {
13
+
14
+ public init() {}
15
+
16
+ public func tracingLocation(location: Location) {
17
+ NotificationCenter.default.post(name: .newLocationSaved, object: self, userInfo: ["Location": location])
18
+ }
19
+
20
+ public func tracingLocationDidFailWithError(error: Error) {
21
+ NSLog("\(error)")
22
+ }
23
+
24
+ public func readLocations() -> [Location] {
25
+ return Locations.getAll()
26
+ }
27
+
28
+ public func eraseLocations() {
29
+ Locations.deleteAll()
30
+ }
31
+
32
+ }
33
+
34
+ extension Notification.Name {
35
+ static let newLocationSaved = Notification.Name("newLocationSaved")
36
+ }