@woosmap/react-native-plugin-geofencing 0.1.2 → 0.1.5
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 +4 -5
- package/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +439 -263
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosLocationReadyListener.java +3 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosRegionReadyListener.java +52 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +11 -3
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +40 -0
- package/ios/DataDistance.swift +14 -23
- package/ios/DataLocation.swift +12 -0
- package/ios/DataRegion.swift +0 -27
- package/ios/MarketingCloudEvents.swift +6 -6
- package/ios/PluginGeofencing.swift +3 -4
- package/package.json +1 -1
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/WoosmapGeofencingPlugin.xcodeproj/project.xcworkspace/xcuserdata/saturn.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/WoosmapGeofencingPlugin.xcodeproj/xcuserdata/saturn.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
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,336 +30,512 @@ 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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
public static final String NAME = "PluginGeofencing";
|
|
39
|
+
|
|
40
|
+
private ReactApplicationContext reactContext;
|
|
41
|
+
private Woosmap woosmap;
|
|
42
|
+
private static final int PERMISSIONS_REQUEST_CODE = 150; // random request code
|
|
43
|
+
private Promise mPermissionsRequestPromise;
|
|
44
|
+
private WoosLocationReadyListener locationReadyListener;
|
|
45
|
+
private WoosRegionReadyListener regionReadyListener;
|
|
46
|
+
|
|
47
|
+
public PluginGeofencingModule(ReactApplicationContext reactContext) {
|
|
48
|
+
super(reactContext);
|
|
49
|
+
this.reactContext = reactContext;
|
|
50
|
+
this.reactContext.addLifecycleEventListener(this);
|
|
51
|
+
}
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
/***
|
|
54
|
+
* Return plugin name.
|
|
55
|
+
* @return woosmap native plugin name.which is constant for android and ios.
|
|
56
|
+
*/
|
|
57
|
+
@Override
|
|
58
|
+
@NonNull
|
|
59
|
+
public String getName() {
|
|
60
|
+
return NAME;
|
|
61
|
+
}
|
|
54
62
|
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
// Example method
|
|
65
|
+
// See https://reactnative.dev/docs/native-modules-android
|
|
66
|
+
@ReactMethod
|
|
67
|
+
public void multiply(int a, int b, Promise promise) {
|
|
68
|
+
promise.resolve(a * b);
|
|
69
|
+
}
|
|
62
70
|
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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);
|
|
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
|
+
*/
|
|
78
|
+
@ReactMethod
|
|
79
|
+
public void initialize(ReadableMap map, Promise promise) {
|
|
80
|
+
String trackingProfile = "";
|
|
81
|
+
try {
|
|
82
|
+
if (woosmap != null) {
|
|
83
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
84
|
+
return;
|
|
85
|
+
} else if (hasPermission(false)) {
|
|
86
|
+
//check required permission first
|
|
87
|
+
if (map.hasKey(WoosmapMessageAndKey.profileTrackingKey)) {
|
|
88
|
+
if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.liveTracking)) {
|
|
89
|
+
trackingProfile = Woosmap.ConfigurationProfile.liveTracking;
|
|
90
|
+
} else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.passiveTracking)) {
|
|
91
|
+
trackingProfile = Woosmap.ConfigurationProfile.passiveTracking;
|
|
92
|
+
} else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.visitsTracking)) {
|
|
93
|
+
trackingProfile = Woosmap.ConfigurationProfile.visitsTracking;
|
|
94
|
+
} else {
|
|
95
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
96
|
+
return;
|
|
97
97
|
}
|
|
98
|
-
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
99
|
-
} else {
|
|
100
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
|
|
101
98
|
}
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
woosmap = Woosmap.getInstance().initializeWoosmap(reactContext);
|
|
100
|
+
if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
|
|
101
|
+
WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
|
|
102
|
+
}
|
|
103
|
+
// Set the Delay of Duration data
|
|
104
|
+
WoosmapSettings.numberOfDayDataDuration = 30;
|
|
105
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
106
|
+
this.woosmap.createWoosmapNotifChannel();
|
|
107
|
+
}
|
|
108
|
+
this.woosmap.onResume();
|
|
109
|
+
if (!trackingProfile.isEmpty()) {
|
|
110
|
+
woosmap.startTracking(trackingProfile);
|
|
111
|
+
}
|
|
112
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
113
|
+
} else {
|
|
114
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
|
|
104
115
|
}
|
|
105
|
-
|
|
116
|
+
} catch (Exception ex) {
|
|
117
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
106
118
|
}
|
|
107
119
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/***
|
|
123
|
+
* Checks if Woosmap object is instantiated.
|
|
124
|
+
* @return true if woosmap sdk is initialized else false.
|
|
125
|
+
*/
|
|
126
|
+
private boolean isWoosmapInitialized() {
|
|
127
|
+
if (woosmap == null) {
|
|
128
|
+
return false;
|
|
113
129
|
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
114
132
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
*/
|
|
137
|
+
@ReactMethod
|
|
138
|
+
private void requestPermissions(ReadableArray data, Promise promise) {
|
|
139
|
+
try {
|
|
140
|
+
if (data.isNull(0)) {
|
|
141
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionValueNotProvided);
|
|
142
|
+
}
|
|
143
|
+
boolean isBackground = data.getBoolean(0);
|
|
144
|
+
PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
|
|
145
|
+
mPermissionsRequestPromise = promise;
|
|
146
|
+
if (activity != null) {
|
|
147
|
+
if (Build.VERSION.SDK_INT >= 23) {
|
|
148
|
+
if (isBackground && Build.VERSION.SDK_INT >= 29) {
|
|
149
|
+
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
|
|
150
|
+
} else {
|
|
151
|
+
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
|
|
131
152
|
}
|
|
132
153
|
}
|
|
133
|
-
} catch (Exception ex) {
|
|
134
|
-
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
135
154
|
}
|
|
155
|
+
} catch (Exception ex) {
|
|
156
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
136
157
|
}
|
|
158
|
+
}
|
|
137
159
|
|
|
138
160
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
161
|
+
@Override
|
|
162
|
+
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
163
|
+
if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
|
|
164
|
+
providePermissionStatus(mPermissionsRequestPromise);
|
|
165
|
+
mPermissionsRequestPromise = null;
|
|
146
166
|
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
147
169
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
170
|
+
/***
|
|
171
|
+
* Provide status of foreground and background location permission.
|
|
172
|
+
* @param promise React native callback context.
|
|
173
|
+
*/
|
|
174
|
+
private void providePermissionStatus(final Promise promise) {
|
|
175
|
+
try {
|
|
176
|
+
if (promise == null) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
Activity activity = getCurrentActivity();
|
|
180
|
+
if (activity == null) {
|
|
181
|
+
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
158
184
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
185
|
+
boolean foreground = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
186
|
+
boolean background = foreground;
|
|
187
|
+
boolean denied = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
|
|
162
188
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
189
|
+
if (Build.VERSION.SDK_INT >= 29) {
|
|
190
|
+
background = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
191
|
+
}
|
|
166
192
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
175
|
-
}
|
|
176
|
-
} catch (Exception ex) {
|
|
193
|
+
if (background) {
|
|
194
|
+
promise.resolve(WoosmapMessageAndKey.backgroundPermissionGrantedMessage);
|
|
195
|
+
} else if (foreground) {
|
|
196
|
+
promise.resolve(WoosmapMessageAndKey.foregroundPermissionGrantedMessage);
|
|
197
|
+
} else if (denied) {
|
|
198
|
+
promise.resolve(WoosmapMessageAndKey.deniedPermissionMessage);
|
|
199
|
+
} else {
|
|
177
200
|
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
178
201
|
}
|
|
202
|
+
} catch (Exception ex) {
|
|
203
|
+
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
179
204
|
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/***
|
|
208
|
+
* Checks if the required location permissions are granted or not.
|
|
209
|
+
* Returns PERMISSION_STATUS_DENIED is no permissions are granted.
|
|
210
|
+
* Returns PERMISSION_STATUS_GRANTED_FOREGROUND if foreground location permission is granted.
|
|
211
|
+
* Returns PERMISSION_STATUS_GRANTED_BACKGROUND if background location permission is granted.
|
|
212
|
+
* Returns UNKNOWN is plugin is unable to determine.
|
|
213
|
+
*/
|
|
214
|
+
@ReactMethod
|
|
215
|
+
public void getPermissionsStatus(final Promise promise) {
|
|
216
|
+
providePermissionStatus(promise);
|
|
217
|
+
}
|
|
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
|
+
*/
|
|
224
|
+
private boolean hasPermission(boolean isBackground) {
|
|
225
|
+
try {
|
|
226
|
+
Activity activity = getCurrentActivity();
|
|
227
|
+
if (activity == null) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (!isBackground) {
|
|
231
|
+
return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
232
|
+
}
|
|
233
|
+
if (isBackground && Build.VERSION.SDK_INT >= 29) {
|
|
234
|
+
return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
235
|
+
}
|
|
180
236
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
providePermissionStatus(promise);
|
|
237
|
+
} catch (Exception ex) {
|
|
238
|
+
Log.e(NAME, ex.toString());
|
|
184
239
|
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
185
242
|
|
|
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
243
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
244
|
+
@Override
|
|
245
|
+
public void onHostResume() {
|
|
246
|
+
if (woosmap != null) {
|
|
247
|
+
woosmap.onResume();
|
|
203
248
|
}
|
|
249
|
+
}
|
|
204
250
|
|
|
251
|
+
@Override
|
|
252
|
+
public void onHostPause() {
|
|
253
|
+
if (woosmap != null) {
|
|
254
|
+
woosmap.onPause();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
205
257
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
258
|
+
@Override
|
|
259
|
+
public void onHostDestroy() {
|
|
260
|
+
if (woosmap != null) {
|
|
261
|
+
woosmap.onDestroy();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
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
|
+
*/
|
|
270
|
+
@ReactMethod
|
|
271
|
+
public void setWoosmapApiKey(ReadableArray data, Promise promise) {
|
|
272
|
+
try {
|
|
273
|
+
if (isWoosmapInitialized()) {
|
|
274
|
+
String apiKey = "";
|
|
275
|
+
if (!data.isNull(0)) {
|
|
276
|
+
apiKey = data.getString(0);
|
|
277
|
+
}
|
|
278
|
+
if (!apiKey.isEmpty()) {
|
|
279
|
+
WoosmapSettings.privateKeyWoosmapAPI = apiKey;
|
|
280
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
281
|
+
} else {
|
|
282
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
210
286
|
}
|
|
287
|
+
|
|
288
|
+
} catch (Exception ex) {
|
|
289
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
211
290
|
}
|
|
291
|
+
}
|
|
212
292
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
*/
|
|
298
|
+
@ReactMethod
|
|
299
|
+
public void startTracking(ReadableArray data, Promise promise) {
|
|
300
|
+
try {
|
|
301
|
+
if (isWoosmapInitialized()) {
|
|
302
|
+
if (data.isNull(0)) {
|
|
303
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.trackingProfileNotProvided);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
String trackingProfile = data.getString(0);
|
|
307
|
+
if (trackingProfile.equals(Woosmap.ConfigurationProfile.liveTracking) ||
|
|
308
|
+
trackingProfile.equals(Woosmap.ConfigurationProfile.passiveTracking) ||
|
|
309
|
+
trackingProfile.equals(Woosmap.ConfigurationProfile.visitsTracking)) {
|
|
310
|
+
woosmap.startTracking(trackingProfile);
|
|
311
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
312
|
+
} else {
|
|
313
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
217
317
|
}
|
|
318
|
+
} catch (Exception ex) {
|
|
319
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
218
320
|
}
|
|
321
|
+
}
|
|
219
322
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
323
|
+
/***
|
|
324
|
+
* Stops tracking
|
|
325
|
+
* @param promise React native callback context.
|
|
326
|
+
*/
|
|
327
|
+
@ReactMethod
|
|
328
|
+
public void stopTracking(Promise promise) {
|
|
329
|
+
try {
|
|
330
|
+
if (isWoosmapInitialized()) {
|
|
331
|
+
woosmap.stopTracking();
|
|
332
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
333
|
+
} else {
|
|
334
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
224
335
|
}
|
|
336
|
+
|
|
337
|
+
} catch (Exception ex) {
|
|
338
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
225
339
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
340
|
+
}
|
|
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
|
+
*/
|
|
347
|
+
@ReactMethod
|
|
348
|
+
public void watchLocation(String watchID, Promise promise) {
|
|
349
|
+
try {
|
|
350
|
+
if (isWoosmapInitialized()) {
|
|
351
|
+
if (locationReadyListener == null) {
|
|
352
|
+
locationReadyListener = new WoosLocationReadyListener(reactContext);
|
|
353
|
+
woosmap.setLocationReadyListener(locationReadyListener);
|
|
354
|
+
promise.resolve(watchID);
|
|
240
355
|
} else {
|
|
241
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
356
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchAlreadyStarted);
|
|
242
357
|
}
|
|
358
|
+
} else {
|
|
359
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
360
|
+
}
|
|
361
|
+
} catch (Exception ex) {
|
|
362
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
363
|
+
}
|
|
364
|
+
}
|
|
243
365
|
|
|
244
|
-
|
|
245
|
-
|
|
366
|
+
/***
|
|
367
|
+
* Clear woosmap location watch.
|
|
368
|
+
* @param watchID Unique String value for location listener.
|
|
369
|
+
* @param promise React native callback context.
|
|
370
|
+
*/
|
|
371
|
+
@ReactMethod
|
|
372
|
+
public void clearLocationWatch(String watchID, Promise promise) {
|
|
373
|
+
try {
|
|
374
|
+
if (locationReadyListener != null) {
|
|
375
|
+
woosmap.setLocationReadyListener(null);
|
|
376
|
+
locationReadyListener = null;
|
|
377
|
+
promise.resolve(watchID);
|
|
378
|
+
} else {
|
|
379
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchNotStarted);
|
|
246
380
|
}
|
|
381
|
+
} catch (Exception ex) {
|
|
382
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
247
383
|
}
|
|
384
|
+
}
|
|
248
385
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
+
*/
|
|
391
|
+
@ReactMethod
|
|
392
|
+
private void setSFMCCredentials(ReadableMap map, Promise promise) {
|
|
393
|
+
try {
|
|
394
|
+
if (isWoosmapInitialized()) {
|
|
395
|
+
if (!map.toHashMap().isEmpty()) {
|
|
396
|
+
HashMap<String, String> SFMCInfo = new HashMap<>();
|
|
397
|
+
String key;
|
|
398
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCauthenticationBaseURIkey)) {
|
|
399
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCauthenticationBaseURIkey);
|
|
400
|
+
}
|
|
401
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCrestBaseURIkey)) {
|
|
402
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCrestBaseURIkey);
|
|
403
|
+
}
|
|
404
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_idkey)) {
|
|
405
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_idkey);
|
|
406
|
+
}
|
|
407
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_secretkey)) {
|
|
408
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_secretkey);
|
|
409
|
+
}
|
|
410
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCcontactKey)) {
|
|
411
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCcontactKey);
|
|
255
412
|
}
|
|
256
413
|
|
|
257
|
-
String
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
263
|
-
} else {
|
|
264
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
414
|
+
Iterator<String> keys = map.toHashMap().keySet().iterator();
|
|
415
|
+
|
|
416
|
+
while (keys.hasNext()) {
|
|
417
|
+
key = keys.next();
|
|
418
|
+
SFMCInfo.put(key, map.getString(key));
|
|
265
419
|
}
|
|
420
|
+
WoosmapSettings.SFMCCredentials = SFMCInfo;
|
|
421
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
266
422
|
} else {
|
|
267
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
423
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.credentialEmptyMessage);
|
|
268
424
|
}
|
|
269
|
-
}
|
|
270
|
-
promise.reject(WoosmapMessageAndKey.errorCode,
|
|
425
|
+
} else {
|
|
426
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
271
427
|
}
|
|
428
|
+
|
|
429
|
+
} catch (Exception ex) {
|
|
430
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
272
431
|
}
|
|
432
|
+
}
|
|
273
433
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
*/
|
|
439
|
+
@ReactMethod
|
|
440
|
+
public void watchRegions(String watchID, Promise promise) {
|
|
441
|
+
try {
|
|
442
|
+
if (isWoosmapInitialized()) {
|
|
443
|
+
if (regionReadyListener == null) {
|
|
444
|
+
regionReadyListener = new WoosRegionReadyListener(reactContext);
|
|
445
|
+
woosmap.setRegionLogReadyListener(regionReadyListener);
|
|
446
|
+
woosmap.setRegionReadyListener(regionReadyListener);
|
|
447
|
+
promise.resolve(watchID);
|
|
280
448
|
} else {
|
|
281
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
449
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchAlreadyStarted);
|
|
282
450
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
451
|
+
} else {
|
|
452
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
286
453
|
}
|
|
454
|
+
} catch (Exception ex) {
|
|
455
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
287
456
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
promise.
|
|
457
|
+
}
|
|
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
|
+
|
|
465
|
+
@ReactMethod
|
|
466
|
+
public void clearRegionsWatch(String watchID, Promise promise) {
|
|
467
|
+
try {
|
|
468
|
+
if (regionReadyListener != null) {
|
|
469
|
+
woosmap.setRegionLogReadyListener(null);
|
|
470
|
+
woosmap.setRegionReadyListener(null);
|
|
471
|
+
regionReadyListener = null;
|
|
472
|
+
promise.resolve(watchID);
|
|
473
|
+
} else {
|
|
474
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchNotStarted);
|
|
304
475
|
}
|
|
476
|
+
} catch (Exception ex) {
|
|
477
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
305
478
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
479
|
+
}
|
|
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
|
+
*/
|
|
486
|
+
@ReactMethod
|
|
487
|
+
public void setPoiRadius(String radius, Promise promise) {
|
|
488
|
+
try {
|
|
489
|
+
if (isWoosmapInitialized()) {
|
|
490
|
+
if (radius.isEmpty()) {
|
|
491
|
+
throw new Exception(WoosmapMessageAndKey.radiusEmptyMessage);
|
|
492
|
+
}
|
|
493
|
+
if (onlyContainsNumbers(radius)) {
|
|
494
|
+
WoosmapSettings.poiRadius = Integer.parseInt(radius);
|
|
495
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
496
|
+
} else if (onlyContainsDouble(radius)) {
|
|
497
|
+
double d = Double.parseDouble(radius);
|
|
498
|
+
WoosmapSettings.poiRadius = (int) Math.round(d);
|
|
499
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
500
|
+
} else {
|
|
501
|
+
WoosmapSettings.poiRadiusNameFromResponse = radius;
|
|
502
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
315
503
|
}
|
|
316
|
-
}
|
|
317
|
-
promise.reject(WoosmapMessageAndKey.errorCode,
|
|
504
|
+
} else {
|
|
505
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
318
506
|
}
|
|
507
|
+
} catch (Exception ex) {
|
|
508
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
319
509
|
}
|
|
320
|
-
|
|
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
|
-
}
|
|
510
|
+
}
|
|
358
511
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
512
|
+
/***
|
|
513
|
+
* Its check string is integer or not.
|
|
514
|
+
* @param text string for checking if it contains only number or not.
|
|
515
|
+
* @return true boolean value if string is only number else false.
|
|
516
|
+
*/
|
|
517
|
+
private boolean onlyContainsNumbers(String text) {
|
|
518
|
+
try {
|
|
519
|
+
Long.parseLong(text);
|
|
520
|
+
return true;
|
|
521
|
+
} catch (NumberFormatException ex) {
|
|
522
|
+
return false;
|
|
363
523
|
}
|
|
524
|
+
}
|
|
364
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
|
+
*/
|
|
531
|
+
private boolean onlyContainsDouble(String text) {
|
|
532
|
+
try {
|
|
533
|
+
Double.parseDouble(text);
|
|
534
|
+
return true;
|
|
535
|
+
} catch (NumberFormatException ex) {
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
365
538
|
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
}
|
package/android/src/main/java/com/reactnativeplugingeofencing/WoosLocationReadyListener.java
CHANGED
|
@@ -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;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package com.reactnativeplugingeofencing;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactApplication;
|
|
6
|
+
import com.facebook.react.ReactInstanceManager;
|
|
7
|
+
import com.facebook.react.ReactNativeHost;
|
|
8
|
+
import com.facebook.react.bridge.ReactContext;
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
10
|
+
import com.webgeoservices.woosmapgeofencing.Woosmap;
|
|
11
|
+
import com.webgeoservices.woosmapgeofencing.database.Region;
|
|
12
|
+
import com.webgeoservices.woosmapgeofencing.database.RegionLog;
|
|
13
|
+
|
|
14
|
+
/***
|
|
15
|
+
* Implements Woosmap Region callbacks
|
|
16
|
+
*/
|
|
17
|
+
public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woosmap.RegionLogReadyListener {
|
|
18
|
+
|
|
19
|
+
private ReactNativeHost reactNativeHost;
|
|
20
|
+
private Context context;
|
|
21
|
+
public WoosRegionReadyListener(Context context){
|
|
22
|
+
this.context=context;
|
|
23
|
+
}
|
|
24
|
+
private void sendEvent(final String eventName, final Object data) {
|
|
25
|
+
final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
|
|
26
|
+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
|
|
27
|
+
if (reactContext != null) {
|
|
28
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
@Override
|
|
32
|
+
public void RegionLogReadyCallback(RegionLog regionLog) {
|
|
33
|
+
try {
|
|
34
|
+
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
|
|
35
|
+
reactNativeHost = reactApplication.getReactNativeHost();
|
|
36
|
+
sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(regionLog));
|
|
37
|
+
}catch (Exception ex){
|
|
38
|
+
sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void RegionReadyCallback(Region region) {
|
|
44
|
+
try {
|
|
45
|
+
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
|
|
46
|
+
reactNativeHost = reactApplication.getReactNativeHost();
|
|
47
|
+
sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(region));
|
|
48
|
+
}catch (Exception ex){
|
|
49
|
+
sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -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="
|
|
13
|
-
protected static String foregroundPermissionGrantedMessage="
|
|
14
|
-
protected static String backgroundPermissionGrantedMessage="
|
|
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";
|
|
@@ -26,6 +27,13 @@ public class WoosmapMessageAndKey {
|
|
|
26
27
|
protected static String SMFCclient_secretkey="client_secret";
|
|
27
28
|
protected static String SMFCcontactKey="contactKey";
|
|
28
29
|
protected static String credentialEmptyMessage="Credentials cannot be empty.";
|
|
30
|
+
protected static String regionSuccessCallbackName="woosmapgeofenceRegionDidChange";
|
|
31
|
+
protected static String regionErrorCallbackName="woosmapgeofenceRegionError";
|
|
32
|
+
protected static String regionWatchAlreadyStarted="Region watch already added";
|
|
33
|
+
protected static String regionWatchNotStarted="region watch not started";
|
|
34
|
+
protected static String radiusEmptyMessage="Radius value can not be empty";
|
|
35
|
+
protected static String invalidRadiusMessage="POI Radius should be an integer or a string.";
|
|
36
|
+
|
|
29
37
|
|
|
30
38
|
|
|
31
39
|
|
|
@@ -7,6 +7,8 @@ import com.facebook.react.bridge.WritableArray;
|
|
|
7
7
|
import com.facebook.react.bridge.WritableMap;
|
|
8
8
|
import com.facebook.react.bridge.WritableNativeArray;
|
|
9
9
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
10
|
+
import com.webgeoservices.woosmapgeofencing.database.Region;
|
|
11
|
+
import com.webgeoservices.woosmapgeofencing.database.RegionLog;
|
|
10
12
|
|
|
11
13
|
import org.json.JSONArray;
|
|
12
14
|
import org.json.JSONException;
|
|
@@ -14,6 +16,9 @@ import org.json.JSONObject;
|
|
|
14
16
|
|
|
15
17
|
import java.util.Iterator;
|
|
16
18
|
|
|
19
|
+
/***
|
|
20
|
+
* Contains misc. utility functions.
|
|
21
|
+
*/
|
|
17
22
|
public class WoosmapUtil {
|
|
18
23
|
private static final String TAG="WoosmapUtil";
|
|
19
24
|
|
|
@@ -30,5 +35,40 @@ public class WoosmapUtil {
|
|
|
30
35
|
}
|
|
31
36
|
return map;
|
|
32
37
|
}
|
|
38
|
+
public static WritableMap getRegionWritableMap(RegionLog regionLog){
|
|
39
|
+
WritableMap map=new WritableNativeMap();
|
|
40
|
+
try{
|
|
41
|
+
map.putDouble("longitude", regionLog.lng);
|
|
42
|
+
map.putDouble("latitude", regionLog.lat);
|
|
43
|
+
map.putDouble("date", regionLog.dateTime);
|
|
44
|
+
map.putBoolean("didenter", regionLog.didEnter);
|
|
45
|
+
map.putString("identifier", regionLog.identifier);
|
|
46
|
+
map.putDouble("radius", regionLog.radius);
|
|
47
|
+
map.putBoolean("frompositiondetection", regionLog.isCurrentPositionInside);
|
|
48
|
+
return map;
|
|
49
|
+
}
|
|
50
|
+
catch (Exception ex){
|
|
51
|
+
Log.e(TAG,ex.toString());
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static WritableMap getRegionWritableMap(Region region){
|
|
57
|
+
WritableMap map=new WritableNativeMap();
|
|
58
|
+
try{
|
|
59
|
+
map.putDouble("longitude", region.lng);
|
|
60
|
+
map.putDouble("latitude", region.lat);
|
|
61
|
+
map.putDouble("date", region.dateTime);
|
|
62
|
+
map.putBoolean("didenter", region.didEnter);
|
|
63
|
+
map.putString("identifier", region.identifier);
|
|
64
|
+
map.putDouble("radius", region.radius);
|
|
65
|
+
map.putBoolean("frompositiondetection", region.isCurrentPositionInside);
|
|
66
|
+
return map;
|
|
67
|
+
}
|
|
68
|
+
catch (Exception ex){
|
|
69
|
+
Log.e(TAG,ex.toString());
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
33
73
|
|
|
34
74
|
}
|
package/ios/DataDistance.swift
CHANGED
|
@@ -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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
//
|
|
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
|
|
46
|
-
var
|
|
47
|
-
|
|
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
|
}
|
package/ios/DataLocation.swift
CHANGED
|
@@ -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) {
|
package/ios/DataRegion.swift
CHANGED
|
@@ -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
|
-
|
|
618
|
-
result["
|
|
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
|
+
"version": "0.1.5",
|
|
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",
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>WoosmapGeofencingPlugin.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
</dict>
|
|
14
|
-
</plist>
|