@woosmap/react-native-plugin-geofencing 0.1.2 → 0.1.3
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/android/src/main/java/com/reactnativeplugingeofencing/PluginGeofencingModule.java +352 -262
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosRegionReadyListener.java +49 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapMessageAndKey.java +7 -0
- package/android/src/main/java/com/reactnativeplugingeofencing/WoosmapUtil.java +37 -0
- 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
|
@@ -32,334 +32,424 @@ import java.util.Iterator;
|
|
|
32
32
|
|
|
33
33
|
@ReactModule(name = PluginGeofencingModule.NAME)
|
|
34
34
|
public class PluginGeofencingModule extends ReactContextBaseJavaModule implements PermissionListener, LifecycleEventListener {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
private WoosRegionReadyListener regionReadyListener;
|
|
43
|
+
|
|
44
|
+
public PluginGeofencingModule(ReactApplicationContext reactContext) {
|
|
45
|
+
super(reactContext);
|
|
46
|
+
this.reactContext = reactContext;
|
|
47
|
+
this.reactContext.addLifecycleEventListener(this);
|
|
48
|
+
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
@Override
|
|
51
|
+
@NonNull
|
|
52
|
+
public String getName() {
|
|
53
|
+
return NAME;
|
|
54
|
+
}
|
|
54
55
|
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
// Example method
|
|
58
|
+
// See https://reactnative.dev/docs/native-modules-android
|
|
59
|
+
@ReactMethod
|
|
60
|
+
public void multiply(int a, int b, Promise promise) {
|
|
61
|
+
promise.resolve(a * b);
|
|
62
|
+
}
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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);
|
|
65
|
+
@ReactMethod
|
|
66
|
+
public void initialize(ReadableMap map, Promise promise) {
|
|
67
|
+
String trackingProfile = "";
|
|
68
|
+
try {
|
|
69
|
+
if (woosmap != null) {
|
|
70
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
71
|
+
return;
|
|
72
|
+
} else if (hasPermission(false)) {
|
|
73
|
+
//check required permission first
|
|
74
|
+
if (map.hasKey(WoosmapMessageAndKey.profileTrackingKey)) {
|
|
75
|
+
if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.liveTracking)) {
|
|
76
|
+
trackingProfile = Woosmap.ConfigurationProfile.liveTracking;
|
|
77
|
+
} else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.passiveTracking)) {
|
|
78
|
+
trackingProfile = Woosmap.ConfigurationProfile.passiveTracking;
|
|
79
|
+
} else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.visitsTracking)) {
|
|
80
|
+
trackingProfile = Woosmap.ConfigurationProfile.visitsTracking;
|
|
81
|
+
} else {
|
|
82
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
83
|
+
return;
|
|
97
84
|
}
|
|
98
|
-
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
99
|
-
} else {
|
|
100
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
woosmap = Woosmap.getInstance().initializeWoosmap(reactContext);
|
|
87
|
+
if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
|
|
88
|
+
WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
|
|
89
|
+
}
|
|
90
|
+
// Set the Delay of Duration data
|
|
91
|
+
WoosmapSettings.numberOfDayDataDuration = 30;
|
|
92
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
93
|
+
this.woosmap.createWoosmapNotifChannel();
|
|
94
|
+
}
|
|
95
|
+
this.woosmap.onResume();
|
|
96
|
+
if (!trackingProfile.isEmpty()) {
|
|
97
|
+
woosmap.startTracking(trackingProfile);
|
|
98
|
+
}
|
|
99
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
100
|
+
} else {
|
|
101
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
|
|
104
102
|
}
|
|
105
|
-
|
|
103
|
+
} catch (Exception ex) {
|
|
104
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private boolean isWoosmapInitialized() {
|
|
110
|
+
if (woosmap == null) {
|
|
111
|
+
return false;
|
|
113
112
|
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
116
|
+
@ReactMethod
|
|
117
|
+
private void requestPermissions(ReadableArray data, Promise promise) {
|
|
118
|
+
try {
|
|
119
|
+
if (data.isNull(0)) {
|
|
120
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionValueNotProvided);
|
|
121
|
+
}
|
|
122
|
+
boolean isBackground = data.getBoolean(0);
|
|
123
|
+
PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
|
|
124
|
+
mPermissionsRequestPromise = promise;
|
|
125
|
+
if (activity != null) {
|
|
126
|
+
if (Build.VERSION.SDK_INT >= 23) {
|
|
127
|
+
if (isBackground && Build.VERSION.SDK_INT >= 29) {
|
|
128
|
+
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
|
|
129
|
+
} else {
|
|
130
|
+
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
} catch (Exception ex) {
|
|
134
|
-
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
135
133
|
}
|
|
134
|
+
} catch (Exception ex) {
|
|
135
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
136
136
|
}
|
|
137
|
+
}
|
|
137
138
|
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
140
|
+
@Override
|
|
141
|
+
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
142
|
+
if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
|
|
143
|
+
providePermissionStatus(mPermissionsRequestPromise);
|
|
144
|
+
mPermissionsRequestPromise = null;
|
|
146
145
|
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
147
148
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
private void providePermissionStatus(final Promise promise) {
|
|
150
|
+
try {
|
|
151
|
+
if (promise == null) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
Activity activity = getCurrentActivity();
|
|
155
|
+
if (activity == null) {
|
|
156
|
+
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
boolean foreground = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
161
|
+
boolean background = foreground;
|
|
162
|
+
boolean denied = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
if (Build.VERSION.SDK_INT >= 29) {
|
|
165
|
+
background = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
166
|
+
}
|
|
166
167
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
175
|
-
}
|
|
176
|
-
} catch (Exception ex) {
|
|
168
|
+
if (background) {
|
|
169
|
+
promise.resolve(WoosmapMessageAndKey.backgroundPermissionGrantedMessage);
|
|
170
|
+
} else if (foreground) {
|
|
171
|
+
promise.resolve(WoosmapMessageAndKey.foregroundPermissionGrantedMessage);
|
|
172
|
+
} else if (denied) {
|
|
173
|
+
promise.resolve(WoosmapMessageAndKey.deniedPermissionMessage);
|
|
174
|
+
} else {
|
|
177
175
|
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
178
176
|
}
|
|
177
|
+
} catch (Exception ex) {
|
|
178
|
+
promise.resolve(WoosmapMessageAndKey.unknownMessage);
|
|
179
179
|
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@ReactMethod
|
|
183
|
+
public void getPermissionsStatus(final Promise promise) {
|
|
184
|
+
providePermissionStatus(promise);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private boolean hasPermission(boolean isBackground) {
|
|
188
|
+
try {
|
|
189
|
+
Activity activity = getCurrentActivity();
|
|
190
|
+
if (activity == null) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (!isBackground) {
|
|
194
|
+
return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
195
|
+
}
|
|
196
|
+
if (isBackground && Build.VERSION.SDK_INT >= 29) {
|
|
197
|
+
return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
198
|
+
}
|
|
180
199
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
providePermissionStatus(promise);
|
|
200
|
+
} catch (Exception ex) {
|
|
201
|
+
Log.e(NAME, ex.toString());
|
|
184
202
|
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
185
205
|
|
|
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
206
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
@Override
|
|
208
|
+
public void onHostResume() {
|
|
209
|
+
if (woosmap != null) {
|
|
210
|
+
woosmap.onResume();
|
|
203
211
|
}
|
|
212
|
+
}
|
|
204
213
|
|
|
214
|
+
@Override
|
|
215
|
+
public void onHostPause() {
|
|
216
|
+
if (woosmap != null) {
|
|
217
|
+
woosmap.onPause();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
205
220
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
221
|
+
@Override
|
|
222
|
+
public void onHostDestroy() {
|
|
223
|
+
if (woosmap != null) {
|
|
224
|
+
woosmap.onDestroy();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@ReactMethod
|
|
229
|
+
public void setWoosmapApiKey(ReadableArray data, Promise promise) {
|
|
230
|
+
try {
|
|
231
|
+
if (isWoosmapInitialized()) {
|
|
232
|
+
String apiKey = "";
|
|
233
|
+
if (!data.isNull(0)) {
|
|
234
|
+
apiKey = data.getString(0);
|
|
235
|
+
}
|
|
236
|
+
if (!apiKey.isEmpty()) {
|
|
237
|
+
WoosmapSettings.privateKeyWoosmapAPI = apiKey;
|
|
238
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
239
|
+
} else {
|
|
240
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
210
244
|
}
|
|
245
|
+
|
|
246
|
+
} catch (Exception ex) {
|
|
247
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
211
248
|
}
|
|
249
|
+
}
|
|
212
250
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
251
|
+
@ReactMethod
|
|
252
|
+
public void startTracking(ReadableArray data, Promise promise) {
|
|
253
|
+
try {
|
|
254
|
+
if (isWoosmapInitialized()) {
|
|
255
|
+
if (data.isNull(0)) {
|
|
256
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.trackingProfileNotProvided);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
String trackingProfile = data.getString(0);
|
|
260
|
+
if (trackingProfile.equals(Woosmap.ConfigurationProfile.liveTracking) ||
|
|
261
|
+
trackingProfile.equals(Woosmap.ConfigurationProfile.passiveTracking) ||
|
|
262
|
+
trackingProfile.equals(Woosmap.ConfigurationProfile.visitsTracking)) {
|
|
263
|
+
woosmap.startTracking(trackingProfile);
|
|
264
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
265
|
+
} else {
|
|
266
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
217
270
|
}
|
|
271
|
+
} catch (Exception ex) {
|
|
272
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
218
273
|
}
|
|
274
|
+
}
|
|
219
275
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
276
|
+
@ReactMethod
|
|
277
|
+
public void stopTracking(Promise promise) {
|
|
278
|
+
try {
|
|
279
|
+
if (isWoosmapInitialized()) {
|
|
280
|
+
woosmap.stopTracking();
|
|
281
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
282
|
+
} else {
|
|
283
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
224
284
|
}
|
|
285
|
+
|
|
286
|
+
} catch (Exception ex) {
|
|
287
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
225
288
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
237
|
-
} else {
|
|
238
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
|
|
239
|
-
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
@ReactMethod
|
|
292
|
+
public void watchLocation(String watchID, Promise promise) {
|
|
293
|
+
try {
|
|
294
|
+
if (isWoosmapInitialized()) {
|
|
295
|
+
if (locationReadyListener == null) {
|
|
296
|
+
locationReadyListener = new WoosLocationReadyListener(reactContext);
|
|
297
|
+
woosmap.setLocationReadyListener(locationReadyListener);
|
|
298
|
+
promise.resolve(watchID);
|
|
240
299
|
} else {
|
|
241
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
300
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchAlreadyStarted);
|
|
242
301
|
}
|
|
302
|
+
} else {
|
|
303
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
304
|
+
}
|
|
305
|
+
} catch (Exception ex) {
|
|
306
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
307
|
+
}
|
|
308
|
+
}
|
|
243
309
|
|
|
244
|
-
|
|
245
|
-
|
|
310
|
+
@ReactMethod
|
|
311
|
+
public void clearLocationWatch(String watchID, Promise promise) {
|
|
312
|
+
try {
|
|
313
|
+
if (locationReadyListener != null) {
|
|
314
|
+
woosmap.setLocationReadyListener(null);
|
|
315
|
+
locationReadyListener = null;
|
|
316
|
+
promise.resolve(watchID);
|
|
317
|
+
} else {
|
|
318
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchNotStarted);
|
|
246
319
|
}
|
|
320
|
+
} catch (Exception ex) {
|
|
321
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
247
322
|
}
|
|
323
|
+
}
|
|
248
324
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
325
|
+
@ReactMethod
|
|
326
|
+
private void setSFMCCredentials(ReadableMap map, Promise promise) {
|
|
327
|
+
try {
|
|
328
|
+
if (isWoosmapInitialized()) {
|
|
329
|
+
if (!map.toHashMap().isEmpty()) {
|
|
330
|
+
HashMap<String, String> SFMCInfo = new HashMap<>();
|
|
331
|
+
String key;
|
|
332
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCauthenticationBaseURIkey)) {
|
|
333
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCauthenticationBaseURIkey);
|
|
334
|
+
}
|
|
335
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCrestBaseURIkey)) {
|
|
336
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCrestBaseURIkey);
|
|
337
|
+
}
|
|
338
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_idkey)) {
|
|
339
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_idkey);
|
|
340
|
+
}
|
|
341
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_secretkey)) {
|
|
342
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_secretkey);
|
|
343
|
+
}
|
|
344
|
+
if (!map.hasKey(WoosmapMessageAndKey.SMFCcontactKey)) {
|
|
345
|
+
throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCcontactKey);
|
|
255
346
|
}
|
|
256
347
|
|
|
257
|
-
String
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
263
|
-
} else {
|
|
264
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
|
|
348
|
+
Iterator<String> keys = map.toHashMap().keySet().iterator();
|
|
349
|
+
|
|
350
|
+
while (keys.hasNext()) {
|
|
351
|
+
key = keys.next();
|
|
352
|
+
SFMCInfo.put(key, map.getString(key));
|
|
265
353
|
}
|
|
354
|
+
WoosmapSettings.SFMCCredentials = SFMCInfo;
|
|
355
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
266
356
|
} else {
|
|
267
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
357
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.credentialEmptyMessage);
|
|
268
358
|
}
|
|
269
|
-
}
|
|
270
|
-
promise.reject(WoosmapMessageAndKey.errorCode,
|
|
359
|
+
} else {
|
|
360
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
271
361
|
}
|
|
362
|
+
|
|
363
|
+
} catch (Exception ex) {
|
|
364
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
272
365
|
}
|
|
366
|
+
}
|
|
273
367
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
368
|
+
@ReactMethod
|
|
369
|
+
public void watchRegions(String watchID, Promise promise) {
|
|
370
|
+
try {
|
|
371
|
+
if (isWoosmapInitialized()) {
|
|
372
|
+
if (regionReadyListener == null) {
|
|
373
|
+
regionReadyListener = new WoosRegionReadyListener(reactContext);
|
|
374
|
+
woosmap.setRegionLogReadyListener(regionReadyListener);
|
|
375
|
+
woosmap.setRegionReadyListener(regionReadyListener);
|
|
376
|
+
promise.resolve(watchID);
|
|
280
377
|
} else {
|
|
281
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.
|
|
378
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchAlreadyStarted);
|
|
282
379
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
380
|
+
} else {
|
|
381
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
286
382
|
}
|
|
383
|
+
} catch (Exception ex) {
|
|
384
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
287
385
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
301
|
-
}
|
|
302
|
-
}catch (Exception ex){
|
|
303
|
-
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
@ReactMethod
|
|
389
|
+
public void clearRegionsWatch(String watchID, Promise promise) {
|
|
390
|
+
try {
|
|
391
|
+
if (regionReadyListener != null) {
|
|
392
|
+
woosmap.setRegionLogReadyListener(null);
|
|
393
|
+
woosmap.setRegionReadyListener(null);
|
|
394
|
+
regionReadyListener = null;
|
|
395
|
+
promise.resolve(watchID);
|
|
396
|
+
} else {
|
|
397
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchNotStarted);
|
|
304
398
|
}
|
|
399
|
+
} catch (Exception ex) {
|
|
400
|
+
promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
|
|
305
401
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
@ReactMethod
|
|
405
|
+
public void setPoiRadius(String radius,Promise promise){
|
|
406
|
+
try{
|
|
407
|
+
if (isWoosmapInitialized()){
|
|
408
|
+
if (radius.isEmpty()){
|
|
409
|
+
throw new Exception(WoosmapMessageAndKey.radiusEmptyMessage);
|
|
410
|
+
}
|
|
411
|
+
if(onlyContainsNumbers(radius)){
|
|
412
|
+
WoosmapSettings.poiRadius=Integer.parseInt(radius);
|
|
413
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
414
|
+
}else if(onlyContainsDouble(radius)){
|
|
415
|
+
double d=Double.parseDouble(radius);
|
|
416
|
+
WoosmapSettings.poiRadius=(int) Math.round(d);
|
|
417
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
313
418
|
}else {
|
|
314
|
-
|
|
419
|
+
WoosmapSettings.poiRadiusNameFromResponse=radius;
|
|
420
|
+
promise.resolve(WoosmapMessageAndKey.successMessage);
|
|
315
421
|
}
|
|
316
|
-
}
|
|
317
|
-
promise.reject(WoosmapMessageAndKey.errorCode,
|
|
422
|
+
}else {
|
|
423
|
+
promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
|
|
318
424
|
}
|
|
319
425
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
}
|
|
426
|
+
catch (Exception ex){
|
|
427
|
+
promise.reject(WoosmapMessageAndKey.errorCode,ex.getMessage());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
358
430
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
431
|
+
/**
|
|
432
|
+
*
|
|
433
|
+
* @param text string for checking if it contains only number or not.
|
|
434
|
+
* @return true boolean value if string is only number else false.
|
|
435
|
+
*/
|
|
436
|
+
private boolean onlyContainsNumbers(String text) {
|
|
437
|
+
try {
|
|
438
|
+
Long.parseLong(text);
|
|
439
|
+
return true;
|
|
440
|
+
} catch (NumberFormatException ex) {
|
|
441
|
+
return false;
|
|
363
442
|
}
|
|
443
|
+
}
|
|
364
444
|
|
|
445
|
+
private boolean onlyContainsDouble(String text) {
|
|
446
|
+
try {
|
|
447
|
+
Double.parseDouble(text);
|
|
448
|
+
return true;
|
|
449
|
+
} catch (NumberFormatException ex) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
365
452
|
}
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woosmap.RegionLogReadyListener {
|
|
15
|
+
|
|
16
|
+
private ReactNativeHost reactNativeHost;
|
|
17
|
+
private Context context;
|
|
18
|
+
public WoosRegionReadyListener(Context context){
|
|
19
|
+
this.context=context;
|
|
20
|
+
}
|
|
21
|
+
private void sendEvent(final String eventName, final Object data) {
|
|
22
|
+
final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
|
|
23
|
+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
|
|
24
|
+
if (reactContext != null) {
|
|
25
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
@Override
|
|
29
|
+
public void RegionLogReadyCallback(RegionLog regionLog) {
|
|
30
|
+
try {
|
|
31
|
+
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
|
|
32
|
+
reactNativeHost = reactApplication.getReactNativeHost();
|
|
33
|
+
sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(regionLog));
|
|
34
|
+
}catch (Exception ex){
|
|
35
|
+
sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public void RegionReadyCallback(Region region) {
|
|
41
|
+
try {
|
|
42
|
+
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
|
|
43
|
+
reactNativeHost = reactApplication.getReactNativeHost();
|
|
44
|
+
sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(region));
|
|
45
|
+
}catch (Exception ex){
|
|
46
|
+
sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -26,6 +26,13 @@ public class WoosmapMessageAndKey {
|
|
|
26
26
|
protected static String SMFCclient_secretkey="client_secret";
|
|
27
27
|
protected static String SMFCcontactKey="contactKey";
|
|
28
28
|
protected static String credentialEmptyMessage="Credentials cannot be empty.";
|
|
29
|
+
protected static String regionSuccessCallbackName="woosmapgeofenceRegionDidChange";
|
|
30
|
+
protected static String regionErrorCallbackName="woosmapgeofenceRegionError";
|
|
31
|
+
protected static String regionWatchAlreadyStarted="Region watch already added";
|
|
32
|
+
protected static String regionWatchNotStarted="region watch not started";
|
|
33
|
+
protected static String radiusEmptyMessage="Radius value can not be empty";
|
|
34
|
+
protected static String invalidRadiusMessage="POI Radius should be an integer or a string.";
|
|
35
|
+
|
|
29
36
|
|
|
30
37
|
|
|
31
38
|
|
|
@@ -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;
|
|
@@ -30,5 +32,40 @@ public class WoosmapUtil {
|
|
|
30
32
|
}
|
|
31
33
|
return map;
|
|
32
34
|
}
|
|
35
|
+
public static WritableMap getRegionWritableMap(RegionLog regionLog){
|
|
36
|
+
WritableMap map=new WritableNativeMap();
|
|
37
|
+
try{
|
|
38
|
+
map.putDouble("longitude", regionLog.lng);
|
|
39
|
+
map.putDouble("latitude", regionLog.lat);
|
|
40
|
+
map.putDouble("date", regionLog.dateTime);
|
|
41
|
+
map.putBoolean("didenter", regionLog.didEnter);
|
|
42
|
+
map.putString("identifier", regionLog.identifier);
|
|
43
|
+
map.putDouble("radius", regionLog.radius);
|
|
44
|
+
map.putBoolean("frompositiondetection", regionLog.isCurrentPositionInside);
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
catch (Exception ex){
|
|
48
|
+
Log.e(TAG,ex.toString());
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public static WritableMap getRegionWritableMap(Region region){
|
|
54
|
+
WritableMap map=new WritableNativeMap();
|
|
55
|
+
try{
|
|
56
|
+
map.putDouble("longitude", region.lng);
|
|
57
|
+
map.putDouble("latitude", region.lat);
|
|
58
|
+
map.putDouble("date", region.dateTime);
|
|
59
|
+
map.putBoolean("didenter", region.didEnter);
|
|
60
|
+
map.putString("identifier", region.identifier);
|
|
61
|
+
map.putDouble("radius", region.radius);
|
|
62
|
+
map.putBoolean("frompositiondetection", region.isCurrentPositionInside);
|
|
63
|
+
return map;
|
|
64
|
+
}
|
|
65
|
+
catch (Exception ex){
|
|
66
|
+
Log.e(TAG,ex.toString());
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
33
70
|
|
|
34
71
|
}
|
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.3",
|
|
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>
|