react-native-radar 3.4.1 → 3.5.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.
@@ -18,7 +18,7 @@ android {
18
18
  minSdkVersion 16
19
19
  targetSdkVersion 31
20
20
  versionCode 1
21
- versionName '3.2.3'
21
+ versionName '3.5.5'
22
22
  }
23
23
  lintOptions {
24
24
  abortOnError false
@@ -45,5 +45,5 @@ repositories {
45
45
 
46
46
  dependencies {
47
47
  api 'com.facebook.react:react-native:+'
48
- api 'io.radar:sdk:3.4.5'
48
+ api 'io.radar:sdk:3.5.4'
49
49
  }
@@ -175,56 +175,41 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
175
175
  }
176
176
 
177
177
  @ReactMethod
178
- public void trackOnce(final Promise promise) {
179
- Radar.trackOnce(new Radar.RadarTrackCallback() {
180
- @Override
181
- public void onComplete(@NonNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarEvent[] events, @Nullable RadarUser user) {
182
- if (promise == null) {
183
- return;
184
- }
185
-
186
- if (status == Radar.RadarStatus.SUCCESS) {
187
- try {
188
- WritableMap map = Arguments.createMap();
189
- map.putString("status", status.toString());
190
- if (location != null) {
191
- map.putMap("location", RNRadarUtils.mapForJson(Radar.jsonForLocation(location)));
192
- }
193
- if (events != null) {
194
- map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
195
- }
196
- if (user != null) {
197
- map.putMap("user", RNRadarUtils.mapForJson(user.toJson()));
198
- }
199
- promise.resolve(map);
200
- } catch (JSONException e) {
201
- Log.e(TAG, "JSONException", e);
202
- promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
203
- }
204
- } else {
205
- promise.reject(status.toString(), status.toString());
178
+ public void trackOnce(ReadableMap optionsMap, final Promise promise) {
179
+
180
+ Location location = null;
181
+ RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM;
182
+ boolean beaconsTrackingOption = false;
183
+
184
+ if (optionsMap != null) {
185
+ if (optionsMap.hasKey("location")) {
186
+ ReadableMap locationMap = optionsMap.getMap("location");
187
+ location = new Location("RNRadarModule");
188
+ double latitude = locationMap.getDouble("latitude");
189
+ double longitude = locationMap.getDouble("longitude");
190
+ float accuracy = (float)locationMap.getDouble("accuracy");
191
+ location.setLatitude(latitude);
192
+ location.setLongitude(longitude);
193
+ location.setAccuracy(accuracy);
194
+ }
195
+ if (optionsMap.hasKey("desiredAccuracy")) {
196
+ String desiredAccuracy = optionsMap.getString("desiredAccuracy").toLowerCase();
197
+ if (desiredAccuracy.equals("none")) {
198
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.NONE;
199
+ } else if (desiredAccuracy.equals("low")) {
200
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.LOW;
201
+ } else if (desiredAccuracy.equals("medium")) {
202
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM;
203
+ } else if (desiredAccuracy.equals("high")) {
204
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH;
206
205
  }
207
206
  }
208
- });
209
- }
210
-
211
- @ReactMethod
212
- public void trackOnce(ReadableMap locationMap, final Promise promise) {
213
- if (locationMap == null) {
214
- this.trackOnce(promise);
215
-
216
- return;
207
+ if (optionsMap.hasKey("beacons")) {
208
+ beaconsTrackingOption = optionsMap.getBoolean("beacons");
209
+ }
217
210
  }
218
211
 
219
- double latitude = locationMap.getDouble("latitude");
220
- double longitude = locationMap.getDouble("longitude");
221
- float accuracy = (float)locationMap.getDouble("accuracy");
222
- Location location = new Location("RNRadarModule");
223
- location.setLatitude(latitude);
224
- location.setLongitude(longitude);
225
- location.setAccuracy(accuracy);
226
-
227
- Radar.trackOnce(location, new Radar.RadarTrackCallback() {
212
+ Radar.RadarTrackCallback trackCallback = new Radar.RadarTrackCallback() {
228
213
  @Override
229
214
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarEvent[] events, @Nullable RadarUser user) {
230
215
  if (promise == null) {
@@ -253,7 +238,13 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
253
238
  promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
254
239
  }
255
240
  }
256
- });
241
+ };
242
+
243
+ if (location != null) {
244
+ Radar.trackOnce(location, trackCallback);
245
+ } else {
246
+ Radar.trackOnce(accuracyLevel, beaconsTrackingOption, trackCallback);
247
+ }
257
248
  }
258
249
 
259
250
  @ReactMethod
@@ -1 +1 @@
1
- github "radarlabs/radar-sdk-ios" "3.4.3"
1
+ github "radarlabs/radar-sdk-ios" "3.5.4"
package/ios/RNRadar.m CHANGED
@@ -179,44 +179,25 @@ RCT_EXPORT_METHOD(getLocation:(RCTPromiseResolveBlock)resolve reject:(RCTPromise
179
179
  }];
180
180
  }
181
181
 
182
- RCT_EXPORT_METHOD(trackOnce:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
182
+ RCT_EXPORT_METHOD(trackOnce:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
183
+ RadarTrackingOptionsDesiredAccuracy desiredAccuracy;
184
+ BOOL beaconsTrackingOption = NO;
185
+ desiredAccuracy = RadarTrackingOptionsDesiredAccuracyMedium;
186
+
183
187
  __block RCTPromiseResolveBlock resolver = resolve;
184
188
  __block RCTPromiseRejectBlock rejecter = reject;
185
189
 
186
- [Radar trackOnceWithCompletionHandler:^(RadarStatus status, CLLocation * _Nullable location, NSArray<RadarEvent *> * _Nullable events, RadarUser * _Nullable user) {
187
- if (status == RadarStatusSuccess && resolver) {
188
- NSMutableDictionary *dict = [NSMutableDictionary new];
189
- [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
190
- if (location) {
191
- [dict setObject:[Radar dictionaryForLocation:location] forKey:@"location"];
192
- }
193
- if (events) {
194
- [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
195
- }
196
- if (user) {
197
- [dict setObject:[user dictionaryValue] forKey:@"user"];
198
- }
199
- resolver(dict);
200
- } else if (rejecter) {
201
- rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
202
- }
203
- resolver = nil;
204
- rejecter = nil;
205
- }];
206
- }
190
+ NSDictionary *locationDict = optionsDict[@"location"];
207
191
 
208
- RCT_EXPORT_METHOD(trackOnce:(NSDictionary *)locationDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
209
192
  CLLocation *location;
210
193
  if (locationDict != nil && [locationDict isKindOfClass:[NSDictionary class]]) {
211
194
  double latitude = [RCTConvert double:locationDict[@"latitude"]];
212
195
  double longitude = [RCTConvert double:locationDict[@"longitude"]];
196
+ double accuracy = [RCTConvert double:locationDict[@"accuracy"]];
213
197
  NSDate *timestamp = [NSDate new];
214
- location = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) altitude:-1 horizontalAccuracy:5 verticalAccuracy:-1 timestamp:timestamp];
198
+ location = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) altitude:-1 horizontalAccuracy:accuracy verticalAccuracy:-1 timestamp:timestamp];
215
199
  }
216
200
 
217
- __block RCTPromiseResolveBlock resolver = resolve;
218
- __block RCTPromiseRejectBlock rejecter = reject;
219
-
220
201
  RadarTrackCompletionHandler completionHandler = ^(RadarStatus status, CLLocation * _Nullable location, NSArray<RadarEvent *> * _Nullable events, RadarUser * _Nullable user) {
221
202
  if (status == RadarStatusSuccess && resolver) {
222
203
  NSMutableDictionary *dict = [NSMutableDictionary new];
@@ -241,10 +222,30 @@ RCT_EXPORT_METHOD(trackOnce:(NSDictionary *)locationDict resolve:(RCTPromiseReso
241
222
  if (location) {
242
223
  [Radar trackOnceWithLocation:location completionHandler:completionHandler];
243
224
  } else {
244
- [Radar trackOnceWithCompletionHandler:completionHandler];
225
+ NSString *accuracy = optionsDict[@"desiredAccuracy"];
226
+
227
+ if (accuracy != nil && [accuracy isKindOfClass:[NSString class]]) {
228
+ NSString *lowerAccuracy = [accuracy lowercaseString];
229
+ if ([lowerAccuracy isEqualToString:@"high"]) {
230
+ desiredAccuracy = RadarTrackingOptionsDesiredAccuracyHigh;
231
+ } else if ([lowerAccuracy isEqualToString:@"medium"]) {
232
+ desiredAccuracy = RadarTrackingOptionsDesiredAccuracyMedium;
233
+ } else if ([lowerAccuracy isEqualToString:@"low"]) {
234
+ desiredAccuracy = RadarTrackingOptionsDesiredAccuracyLow;
235
+ }
236
+ }
237
+
238
+ BOOL beacons = optionsDict[@"beacons"];
239
+
240
+ if (beacons) {
241
+ beaconsTrackingOption = beacons;
242
+ }
243
+
244
+ [Radar trackOnceWithDesiredAccuracy:desiredAccuracy beacons:beaconsTrackingOption completionHandler:completionHandler];
245
245
  }
246
246
  }
247
247
 
248
+
248
249
  RCT_EXPORT_METHOD(startTrackingEfficient) {
249
250
  [Radar startTrackingWithOptions:RadarTrackingOptions.presetEfficient];
250
251
  }
package/js/index.js CHANGED
@@ -34,9 +34,17 @@ const getLocation = () => (
34
34
  NativeModules.RNRadar.getLocation()
35
35
  );
36
36
 
37
- const trackOnce = location => (
38
- NativeModules.RNRadar.trackOnce(location)
39
- );
37
+ const trackOnce = options => {
38
+ let backCompatibleOptions = options;
39
+ if (options && options.latitude) {
40
+ backCompatibleOptions = {
41
+ location: {
42
+ ...options
43
+ }
44
+ }
45
+ }
46
+ return NativeModules.RNRadar.trackOnce(backCompatibleOptions)
47
+ };
40
48
 
41
49
  const startTrackingEfficient = () => (
42
50
  NativeModules.RNRadar.startTrackingEfficient()
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
4
  "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.4.1",
6
+ "version": "3.5.5",
7
7
  "main": "js/index.js",
8
8
  "files": [
9
9
  "android",
@@ -15,5 +15,5 @@ Pod::Spec.new do |s|
15
15
  s.platform = :ios, "10.0"
16
16
 
17
17
  s.dependency "React"
18
- s.dependency "RadarSDK", "~> 3.4.3"
18
+ s.dependency "RadarSDK", "~> 3.5.4"
19
19
  end