react-native-radar 3.1.5 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/react-native-radar.svg)](https://www.npmjs.com/package/react-native-radar)
4
4
 
5
- [Radar](https://radar.io) is the leading geofencing and location tracking platform.
5
+ [Radar](https://radar.com) is the leading geofencing and location tracking platform.
6
6
 
7
7
  The Radar SDK abstracts away cross-platform differences between location services, allowing you to add geofencing, location tracking, trip tracking, geocoding, and search to your apps with just a few lines of code.
8
8
 
9
9
  ## Documentation
10
10
 
11
- See the Radar overview documentation [here](https://radar.io/documentation).
11
+ See the Radar overview documentation [here](https://radar.com/documentation).
12
12
 
13
- Then, see the Radar React Native module documentation [here](https://radar.io/documentation/sdk/react-native).
13
+ Then, see the Radar React Native module documentation [here](https://radar.com/documentation/sdk/react-native).
14
14
 
15
15
  ## Examples
16
16
 
@@ -18,4 +18,4 @@ See an example app in `example/`.
18
18
 
19
19
  ## Support
20
20
 
21
- Have questions? We're here to help! Email us at [support@radar.io](mailto:support@radar.io).
21
+ Have questions? We're here to help! Email us at [support@radar.com](mailto:support@radar.com).
@@ -1,26 +1,24 @@
1
1
  buildscript {
2
2
  repositories {
3
- maven {
4
- url 'https://maven.google.com'
5
- }
6
- jcenter()
3
+ google()
4
+ mavenCentral()
7
5
  }
8
6
 
9
7
  dependencies {
10
- classpath 'com.android.tools.build:gradle:3.1.3'
8
+ classpath 'com.android.tools.build:gradle:7.0.3'
11
9
  }
12
10
  }
13
11
 
14
12
  apply plugin: 'com.android.library'
15
13
 
16
14
  android {
17
- compileSdkVersion 29
15
+ compileSdkVersion 31
18
16
 
19
17
  defaultConfig {
20
18
  minSdkVersion 16
21
- targetSdkVersion 29
19
+ targetSdkVersion 31
22
20
  versionCode 1
23
- versionName '3.1.5'
21
+ versionName '3.2.1'
24
22
  }
25
23
  lintOptions {
26
24
  abortOnError false
@@ -28,14 +26,17 @@ android {
28
26
  testOptions {
29
27
  unitTests.returnDefaultValues = true
30
28
  }
29
+ configurations.all {
30
+ resolutionStrategy {
31
+ force 'androidx.core:core:1.6.0'
32
+ force 'androidx.core:core-ktx:1.6.0'
33
+ }
34
+ }
31
35
  }
32
36
 
33
37
  repositories {
34
38
  mavenCentral()
35
- maven {
36
- url 'https://maven.google.com'
37
- }
38
- jcenter()
39
+ google()
39
40
  maven {
40
41
  // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
41
42
  url "$rootDir/../node_modules/react-native/android"
@@ -44,5 +45,5 @@ repositories {
44
45
 
45
46
  dependencies {
46
47
  api 'com.facebook.react:react-native:+'
47
- api 'io.radar:sdk:3.1.14'
48
+ api 'io.radar:sdk:3.2.4'
48
49
  }
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3
3
  distributionPath=wrapper/dists
4
4
  zipStoreBase=GRADLE_USER_HOME
5
5
  zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
@@ -0,0 +1 @@
1
+ android.useAndroidX=true
@@ -1,15 +1,4 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="io.radar.react">
3
3
 
4
- <application>
5
- <receiver
6
- android:name="io.radar.react.RNRadarReceiver"
7
- android:enabled="true"
8
- android:exported="false">
9
- <intent-filter>
10
- <action android:name="io.radar.sdk.RECEIVED" />
11
- </intent-filter>
12
- </receiver>
13
- </application>
14
-
15
4
  </manifest>
@@ -19,6 +19,8 @@ import com.facebook.react.bridge.ReactMethod;
19
19
  import com.facebook.react.bridge.ReadableArray;
20
20
  import com.facebook.react.bridge.ReadableMap;
21
21
  import com.facebook.react.bridge.WritableMap;
22
+ import com.facebook.react.modules.core.PermissionAwareActivity;
23
+ import com.facebook.react.modules.core.PermissionListener;
22
24
  import io.radar.sdk.Radar;
23
25
  import io.radar.sdk.RadarTrackingOptions;
24
26
  import io.radar.sdk.RadarTripOptions;
@@ -29,6 +31,7 @@ import io.radar.sdk.model.RadarGeofence;
29
31
  import io.radar.sdk.model.RadarPlace;
30
32
  import io.radar.sdk.model.RadarRouteMatrix;
31
33
  import io.radar.sdk.model.RadarRoutes;
34
+ import io.radar.sdk.model.RadarTrip;
32
35
  import io.radar.sdk.model.RadarUser;
33
36
 
34
37
  import org.json.JSONException;
@@ -36,12 +39,15 @@ import org.json.JSONObject;
36
39
 
37
40
  import java.util.EnumSet;
38
41
 
39
- public class RNRadarModule extends ReactContextBaseJavaModule {
42
+ public class RNRadarModule extends ReactContextBaseJavaModule implements PermissionListener {
40
43
 
41
44
  private static final String TAG = "RNRadarModule";
45
+ private static final int PERMISSIONS_REQUEST_CODE = 20160525; // random request code (Radar's birthday!)
46
+ private Promise mPermissionsRequestPromise;
42
47
 
43
48
  public RNRadarModule(ReactApplicationContext reactContext) {
44
49
  super(reactContext);
50
+ Radar.setReceiver(new RNRadarReceiver());
45
51
  }
46
52
 
47
53
  @Override
@@ -82,7 +88,7 @@ public class RNRadarModule extends ReactContextBaseJavaModule {
82
88
  }
83
89
 
84
90
  @ReactMethod
85
- public void getPermissionsStatus(Promise promise) {
91
+ public void getPermissionsStatus(final Promise promise) {
86
92
  if (promise == null) {
87
93
  return;
88
94
  }
@@ -114,16 +120,25 @@ public class RNRadarModule extends ReactContextBaseJavaModule {
114
120
  }
115
121
  }
116
122
 
123
+ @Override
124
+ public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
125
+ if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
126
+ getPermissionsStatus(mPermissionsRequestPromise);
127
+ mPermissionsRequestPromise = null;
128
+ }
129
+ return true;
130
+ }
131
+
117
132
  @ReactMethod
118
- public void requestPermissions(boolean background) {
119
- Activity activity = getCurrentActivity();
133
+ public void requestPermissions(boolean background, final Promise promise) {
134
+ PermissionAwareActivity activity = (PermissionAwareActivity)getCurrentActivity();
135
+ mPermissionsRequestPromise = promise;
120
136
  if (activity != null) {
121
137
  if (Build.VERSION.SDK_INT >= 23) {
122
- int requestCode = 0;
123
138
  if (background && Build.VERSION.SDK_INT >= 29) {
124
- ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION }, requestCode);
139
+ activity.requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION }, PERMISSIONS_REQUEST_CODE, this);
125
140
  } else {
126
- ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, requestCode);
141
+ activity.requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSIONS_REQUEST_CODE, this);
127
142
  }
128
143
  }
129
144
  }
@@ -316,41 +331,165 @@ public class RNRadarModule extends ReactContextBaseJavaModule {
316
331
  }
317
332
 
318
333
  @ReactMethod
319
- public void startTrip(ReadableMap optionsMap) {
334
+ public void startTrip(ReadableMap optionsMap, final Promise promise) {
320
335
  try {
321
336
  JSONObject optionsObj = RNRadarUtils.jsonForMap(optionsMap);
322
337
  RadarTripOptions options = RadarTripOptions.fromJson(optionsObj);
323
338
  Radar.startTrip(options, new Radar.RadarTripCallback() {
324
339
  @Override
325
- public void onComplete(@NonNull Radar.RadarStatus status) {
326
-
340
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
341
+ if (promise == null) {
342
+ return;
343
+ }
344
+ try {
345
+ if (status == Radar.RadarStatus.SUCCESS) {
346
+ WritableMap map = Arguments.createMap();
347
+ map.putString("status", status.toString());
348
+ if (trip != null) {
349
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
350
+ }
351
+ if (events != null) {
352
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
353
+ }
354
+ promise.resolve(map);
355
+ } else {
356
+ promise.reject(status.toString(), status.toString());
357
+ }
358
+ } catch (JSONException e) {
359
+ Log.e(TAG, "JSONException", e);
360
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
361
+ }
327
362
  }
328
363
  });
329
364
  } catch (JSONException e) {
330
365
  Log.e(TAG, "JSONException", e);
366
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
331
367
  }
332
368
  }
333
369
 
334
370
  @ReactMethod
335
- public void completeTrip() {
371
+ public void completeTrip(final Promise promise) {
336
372
  Radar.completeTrip(new Radar.RadarTripCallback() {
337
373
  @Override
338
- public void onComplete(@NonNull Radar.RadarStatus status) {
339
-
374
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
375
+ if (promise == null) {
376
+ return;
377
+ }
378
+ try {
379
+ if (status == Radar.RadarStatus.SUCCESS) {
380
+ WritableMap map = Arguments.createMap();
381
+ map.putString("status", status.toString());
382
+ if (trip != null) {
383
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
384
+ }
385
+ if (events != null) {
386
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
387
+ }
388
+ promise.resolve(map);
389
+ } else {
390
+ promise.reject(status.toString(), status.toString());
391
+ }
392
+ } catch (JSONException e) {
393
+ Log.e(TAG, "JSONException", e);
394
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
395
+ }
340
396
  }
341
397
  });
342
398
  }
343
399
 
344
400
  @ReactMethod
345
- public void cancelTrip() {
401
+ public void cancelTrip(final Promise promise) {
346
402
  Radar.cancelTrip(new Radar.RadarTripCallback() {
347
403
  @Override
348
- public void onComplete(@NonNull Radar.RadarStatus status) {
349
-
404
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
405
+ if (promise == null) {
406
+ return;
407
+ }
408
+ try {
409
+ if (status == Radar.RadarStatus.SUCCESS) {
410
+ WritableMap map = Arguments.createMap();
411
+ map.putString("status", status.toString());
412
+ if (trip != null) {
413
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
414
+ }
415
+ if (events != null) {
416
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
417
+ }
418
+ promise.resolve(map);
419
+ } else {
420
+ promise.reject(status.toString(), status.toString());
421
+ }
422
+ } catch (JSONException e) {
423
+ Log.e(TAG, "JSONException", e);
424
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
425
+ }
350
426
  }
351
427
  });
352
428
  }
353
429
 
430
+ @ReactMethod
431
+ public void updateTrip(ReadableMap optionsMap, final Promise promise) {
432
+
433
+ try {
434
+ JSONObject optionsObj = RNRadarUtils.jsonForMap(optionsMap);
435
+ RadarTripOptions options = RadarTripOptions.fromJson(optionsObj.getJSONObject("options"));
436
+ RadarTrip.RadarTripStatus status = RadarTrip.RadarTripStatus.UNKNOWN;
437
+
438
+ if (optionsObj.has("status")) {
439
+ String statusStr = optionsObj.getString("status");
440
+ if (statusStr != null) {
441
+ if (statusStr.equalsIgnoreCase("started")) {
442
+ status = RadarTrip.RadarTripStatus.STARTED;
443
+ } else if (statusStr.equalsIgnoreCase("approaching")) {
444
+ status = RadarTrip.RadarTripStatus.APPROACHING;
445
+ } else if (statusStr.equalsIgnoreCase("arrived")) {
446
+ status = RadarTrip.RadarTripStatus.ARRIVED;
447
+ } else if (statusStr.equalsIgnoreCase("completed")) {
448
+ status = RadarTrip.RadarTripStatus.COMPLETED;
449
+ } else if (statusStr.equalsIgnoreCase("canceled")) {
450
+ status = RadarTrip.RadarTripStatus.CANCELED;
451
+ } else if (statusStr.equalsIgnoreCase("unknown")) {
452
+ status = RadarTrip.RadarTripStatus.UNKNOWN;
453
+ } else {
454
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
455
+ }
456
+ }
457
+ } else {
458
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
459
+ }
460
+
461
+ Radar.updateTrip(options, status, new Radar.RadarTripCallback() {
462
+ @Override
463
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
464
+ if (promise == null) {
465
+ return;
466
+ }
467
+ try {
468
+ if (status == Radar.RadarStatus.SUCCESS) {
469
+ WritableMap map = Arguments.createMap();
470
+ map.putString("status", status.toString());
471
+ if (trip != null) {
472
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
473
+ }
474
+ if (events != null) {
475
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
476
+ }
477
+ promise.resolve(map);
478
+ } else {
479
+ promise.reject(status.toString(), status.toString());
480
+ }
481
+ } catch (JSONException e) {
482
+ Log.e(TAG, "JSONException", e);
483
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
484
+ }
485
+ }
486
+ });
487
+ } catch (JSONException e) {
488
+ Log.e(TAG, "JSONException", e);
489
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
490
+ }
491
+ }
492
+
354
493
  @ReactMethod
355
494
  public void getContext(final Promise promise) {
356
495
  if (promise == null) {
@@ -553,8 +692,10 @@ public class RNRadarModule extends ReactContextBaseJavaModule {
553
692
  near.setLatitude(latitude);
554
693
  near.setLongitude(longitude);
555
694
  int limit = optionsMap.hasKey("limit") ? optionsMap.getInt("limit") : 10;
695
+ String country = optionsMap.hasKey("country") ? optionsMap.getString("country") : null;
696
+ String[] layers = optionsMap.hasKey("layers") ? RNRadarUtils.stringArrayForArray(optionsMap.getArray("layers")) : null;
556
697
 
557
- Radar.autocomplete(query, near, limit, new Radar.RadarGeocodeCallback() {
698
+ Radar.autocomplete(query, near, layers, limit, country, new Radar.RadarGeocodeCallback() {
558
699
  @Override
559
700
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarAddress[] addresses) {
560
701
  if (status == Radar.RadarStatus.SUCCESS) {
@@ -5,6 +5,7 @@ import android.location.Location;
5
5
  import android.util.Log;
6
6
 
7
7
  import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
8
9
 
9
10
  import com.facebook.react.ReactApplication;
10
11
  import com.facebook.react.ReactInstanceManager;
@@ -23,49 +24,27 @@ import java.util.concurrent.atomic.AtomicInteger;
23
24
  public class RNRadarReceiver extends RadarReceiver {
24
25
 
25
26
  private ReactNativeHost reactNativeHost;
26
- private PendingResult result;
27
- private AtomicInteger pendingCount = new AtomicInteger(0);
28
27
  private static final String TAG = "RNRadarReceiver";
29
28
 
30
- private void invokeSendEvent(ReactContext reactContext, String eventName, Object data) {
31
- reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
32
- }
33
-
34
29
  private void sendEvent(final String eventName, final Object data) {
35
30
  final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
36
31
  ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
37
- if (reactContext == null) {
38
- if (result == null) {
39
- result = goAsync();
40
- }
41
- pendingCount.incrementAndGet();
42
- reactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
43
- @Override
44
- public void onReactContextInitialized(ReactContext reactContext) {
45
- invokeSendEvent(reactContext, eventName, data);
46
- reactInstanceManager.removeReactInstanceEventListener(this);
47
- if (pendingCount.decrementAndGet() == 0) {
48
- result.finish();
49
- }
50
- }
51
- });
52
- if (!reactInstanceManager.hasStartedCreatingInitialContext()) {
53
- reactInstanceManager.createReactContextInBackground();
54
- }
55
- } else {
56
- invokeSendEvent(reactContext, eventName, data);
32
+ if (reactContext != null) {
33
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
57
34
  }
58
35
  }
59
36
 
60
37
  @Override
61
- public void onEventsReceived(@NonNull Context context, @NonNull RadarEvent[] events, @NonNull RadarUser user) {
38
+ public void onEventsReceived(@NonNull Context context, @NonNull RadarEvent[] events, @Nullable RadarUser user) {
62
39
  try {
63
40
  ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
64
41
  reactNativeHost = reactApplication.getReactNativeHost();
65
42
 
66
43
  WritableMap map = Arguments.createMap();
67
44
  map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
68
- map.putMap("user", RNRadarUtils.mapForJson(user.toJson()));
45
+ if (user != null) {
46
+ map.putMap("user", RNRadarUtils.mapForJson(user.toJson()));
47
+ }
69
48
 
70
49
  sendEvent("events", map);
71
50
  } catch (Exception e) {
@@ -1 +1 @@
1
- github "radarlabs/radar-sdk-ios" "3.1.7"
1
+ github "radarlabs/radar-sdk-ios" "3.2.3"
package/ios/RNRadar.h CHANGED
@@ -2,6 +2,6 @@
2
2
  #import <React/RCTBridgeModule.h>
3
3
  #import <React/RCTEventEmitter.h>
4
4
 
5
- @interface RNRadar : RCTEventEmitter <RadarDelegate, RCTBridgeModule>
5
+ @interface RNRadar : RCTEventEmitter <RadarDelegate, RCTBridgeModule, CLLocationManagerDelegate>
6
6
 
7
7
  @end
package/ios/RNRadar.m CHANGED
@@ -7,6 +7,7 @@
7
7
  @implementation RNRadar {
8
8
  BOOL hasListeners;
9
9
  CLLocationManager *locationManager;
10
+ RCTPromiseResolveBlock permissionsRequestResolver;
10
11
  }
11
12
 
12
13
  RCT_EXPORT_MODULE();
@@ -16,10 +17,18 @@ RCT_EXPORT_MODULE();
16
17
  if (self) {
17
18
  [Radar setDelegate:self];
18
19
  locationManager = [CLLocationManager new];
20
+ locationManager.delegate = self;
19
21
  }
20
22
  return self;
21
23
  }
22
24
 
25
+ - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
26
+ if (permissionsRequestResolver) {
27
+ [self getPermissionsStatusWithResolver:permissionsRequestResolver rejecter:nil];
28
+ permissionsRequestResolver = nil;
29
+ }
30
+ }
31
+
23
32
  + (BOOL)requiresMainQueueSetup {
24
33
  return YES;
25
34
  }
@@ -40,13 +49,14 @@ RCT_EXPORT_MODULE();
40
49
  hasListeners = NO;
41
50
  }
42
51
 
43
- - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser *)user {
52
+ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Nullable )user {
44
53
  if (hasListeners) {
45
- [self sendEventWithName:@"events" body:@{
46
- @"events": [RadarEvent arrayForEvents:events],
47
- @"user": [user dictionaryValue]
48
-
49
- }];
54
+ NSMutableDictionary *body = [NSMutableDictionary new];
55
+ [body setValue:[RadarEvent arrayForEvents:events] forKey:@"events"];
56
+ if (user) {
57
+ [body setValue:[user dictionaryValue] forKey:@"user"];
58
+ }
59
+ [self sendEventWithName:@"events" body:body];
50
60
  }
51
61
  }
52
62
 
@@ -64,7 +74,7 @@ RCT_EXPORT_MODULE();
64
74
  [self sendEventWithName:@"clientLocation" body:@{
65
75
  @"location": [Radar dictionaryForLocation:location],
66
76
  @"stopped": @(stopped),
67
- @"source": [Radar stringForSource:source]
77
+ @"source": [Radar stringForLocationSource:source]
68
78
  }];
69
79
  }
70
80
  }
@@ -135,11 +145,16 @@ RCT_REMAP_METHOD(getPermissionsStatus, getPermissionsStatusWithResolver:(RCTProm
135
145
  resolve(statusStr);
136
146
  }
137
147
 
138
- RCT_EXPORT_METHOD(requestPermissions:(BOOL)background) {
139
- if (background) {
148
+ RCT_EXPORT_METHOD(requestPermissions:(BOOL)background resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
149
+ permissionsRequestResolver = resolve;
150
+
151
+ CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
152
+ if (background && status == kCLAuthorizationStatusAuthorizedWhenInUse) {
140
153
  [locationManager requestAlwaysAuthorization];
141
- } else {
154
+ } else if (status == kCLAuthorizationStatusNotDetermined) {
142
155
  [locationManager requestWhenInUseAuthorization];
156
+ } else {
157
+ [self getPermissionsStatusWithResolver:resolve rejecter:reject];
143
158
  }
144
159
  }
145
160
 
@@ -231,15 +246,15 @@ RCT_EXPORT_METHOD(trackOnce:(NSDictionary *)locationDict resolve:(RCTPromiseReso
231
246
  }
232
247
 
233
248
  RCT_EXPORT_METHOD(startTrackingEfficient) {
234
- [Radar startTrackingWithOptions:RadarTrackingOptions.efficient];
249
+ [Radar startTrackingWithOptions:RadarTrackingOptions.presetEfficient];
235
250
  }
236
251
 
237
252
  RCT_EXPORT_METHOD(startTrackingResponsive) {
238
- [Radar startTrackingWithOptions:RadarTrackingOptions.responsive];
253
+ [Radar startTrackingWithOptions:RadarTrackingOptions.presetResponsive];
239
254
  }
240
255
 
241
256
  RCT_EXPORT_METHOD(startTrackingContinuous) {
242
- [Radar startTrackingWithOptions:RadarTrackingOptions.continuous];
257
+ [Radar startTrackingWithOptions:RadarTrackingOptions.presetContinuous];
243
258
  }
244
259
 
245
260
  RCT_EXPORT_METHOD(startTrackingCustom:(NSDictionary *)optionsDict) {
@@ -299,17 +314,140 @@ RCT_EXPORT_METHOD(rejectEvent:(NSString *)eventId) {
299
314
  [Radar rejectEventId:eventId];
300
315
  }
301
316
 
302
- RCT_EXPORT_METHOD(startTrip:(NSDictionary *)optionsDict) {
317
+ RCT_EXPORT_METHOD(startTrip:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
303
318
  RadarTripOptions *options = [RadarTripOptions tripOptionsFromDictionary:optionsDict];
304
- [Radar startTripWithOptions:options];
319
+
320
+ __block RCTPromiseResolveBlock resolver = resolve;
321
+ __block RCTPromiseRejectBlock rejecter = reject;
322
+
323
+ [Radar startTripWithOptions:options completionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
324
+
325
+ if (status == RadarStatusSuccess && resolver) {
326
+ NSMutableDictionary *dict = [NSMutableDictionary new];
327
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
328
+ if (trip) {
329
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
330
+ }
331
+ if (events) {
332
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
333
+ }
334
+ resolver(dict);
335
+ } else if (rejecter) {
336
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
337
+ }
338
+ resolver = nil;
339
+ rejecter = nil;
340
+ }];
305
341
  }
306
342
 
307
- RCT_EXPORT_METHOD(completeTrip) {
308
- [Radar completeTrip];
343
+ RCT_EXPORT_METHOD(completeTrip:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
344
+
345
+ __block RCTPromiseResolveBlock resolver = resolve;
346
+ __block RCTPromiseRejectBlock rejecter = reject;
347
+
348
+ [Radar completeTripWithCompletionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
349
+ if (status == RadarStatusSuccess && resolver) {
350
+ NSMutableDictionary *dict = [NSMutableDictionary new];
351
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
352
+ if (trip) {
353
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
354
+ }
355
+ if (events) {
356
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
357
+ }
358
+ resolver(dict);
359
+ } else if (rejecter) {
360
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
361
+ }
362
+ resolver = nil;
363
+ rejecter = nil;
364
+ }];
309
365
  }
310
366
 
311
- RCT_EXPORT_METHOD(cancelTrip) {
312
- [Radar cancelTrip];
367
+ RCT_EXPORT_METHOD(cancelTrip:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
368
+ __block RCTPromiseResolveBlock resolver = resolve;
369
+ __block RCTPromiseRejectBlock rejecter = reject;
370
+
371
+ [Radar cancelTripWithCompletionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
372
+ if (status == RadarStatusSuccess && resolver) {
373
+ NSMutableDictionary *dict = [NSMutableDictionary new];
374
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
375
+ if (trip) {
376
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
377
+ }
378
+ if (events) {
379
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
380
+ }
381
+ resolver(dict);
382
+ } else if (rejecter) {
383
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
384
+ }
385
+ resolver = nil;
386
+ rejecter = nil;
387
+ }];
388
+ }
389
+
390
+ RCT_EXPORT_METHOD(updateTrip:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
391
+ if (optionsDict == nil) {
392
+ if (reject) {
393
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
394
+ }
395
+
396
+ return;
397
+ }
398
+
399
+ RadarTripOptions *options = [RadarTripOptions tripOptionsFromDictionary:optionsDict[@"options"]];
400
+ NSString *statusStr = optionsDict[@"status"];
401
+
402
+ RadarTripStatus status = RadarTripStatusUnknown;
403
+ if (statusStr) {
404
+ if ([statusStr isEqualToString:@"started"]) {
405
+ status = RadarTripStatusStarted;
406
+ } else if ([statusStr isEqualToString:@"approaching"]) {
407
+ status = RadarTripStatusApproaching;
408
+ } else if ([statusStr isEqualToString:@"arrived"]) {
409
+ status = RadarTripStatusArrived;
410
+ } else if ([statusStr isEqualToString:@"completed"]) {
411
+ status = RadarTripStatusCompleted;
412
+ } else if ([statusStr isEqualToString:@"canceled"]) {
413
+ status = RadarTripStatusCanceled;
414
+ } else if ([statusStr isEqualToString:@"unknown"]) {
415
+ status = RadarTripStatusUnknown;
416
+ } else {
417
+ if (reject) {
418
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
419
+ }
420
+
421
+ return;
422
+ }
423
+ } else {
424
+ if (reject) {
425
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
426
+ }
427
+
428
+ return;
429
+ }
430
+
431
+ __block RCTPromiseResolveBlock resolver = resolve;
432
+ __block RCTPromiseRejectBlock rejecter = reject;
433
+
434
+ [Radar updateTripWithOptions:options status:status completionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
435
+ if (status == RadarStatusSuccess && resolver) {
436
+ NSMutableDictionary *dict = [NSMutableDictionary new];
437
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
438
+ if (trip) {
439
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
440
+ }
441
+ if (events) {
442
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
443
+ }
444
+ resolver(dict);
445
+ } else if (rejecter) {
446
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
447
+ }
448
+ resolver = nil;
449
+ rejecter = nil;
450
+ }];
313
451
  }
314
452
 
315
453
  RCT_EXPORT_METHOD(getContext:(NSDictionary *)locationDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
@@ -505,10 +643,13 @@ RCT_EXPORT_METHOD(autocomplete:(NSDictionary *)optionsDict resolve:(RCTPromiseRe
505
643
  limit = 10;
506
644
  }
507
645
 
646
+ NSArray *layers = optionsDict[@"layers"];
647
+ NSString *country = optionsDict[@"country"];
648
+
508
649
  __block RCTPromiseResolveBlock resolver = resolve;
509
650
  __block RCTPromiseRejectBlock rejecter = reject;
510
651
 
511
- [Radar autocompleteQuery:query near:near limit:limit completionHandler:^(RadarStatus status, NSArray<RadarAddress *> * _Nullable addresses) {
652
+ [Radar autocompleteQuery:query near:near layers:layers limit:limit country:country completionHandler:^(RadarStatus status, NSArray<RadarAddress *> * _Nullable addresses) {
512
653
  if (status == RadarStatusSuccess && resolver) {
513
654
  NSMutableDictionary *dict = [NSMutableDictionary new];
514
655
  [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
package/js/index.js CHANGED
@@ -26,9 +26,9 @@ const getPermissionsStatus = () => (
26
26
  NativeModules.RNRadar.getPermissionsStatus()
27
27
  );
28
28
 
29
- const requestPermissions = (background) => {
30
- NativeModules.RNRadar.requestPermissions(background);
31
- };
29
+ const requestPermissions = background => (
30
+ NativeModules.RNRadar.requestPermissions(background)
31
+ );
32
32
 
33
33
  const getLocation = () => (
34
34
  NativeModules.RNRadar.getLocation()
@@ -74,6 +74,10 @@ const cancelTrip = () => (
74
74
  NativeModules.RNRadar.cancelTrip()
75
75
  );
76
76
 
77
+ const updateTrip = options => (
78
+ NativeModules.RNRadar.updateTrip(options)
79
+ );
80
+
77
81
  const acceptEvent = (eventId, verifiedPlaceId) => (
78
82
  NativeModules.RNRadar.acceptEvent(eventId, verifiedPlaceId)
79
83
  );
@@ -148,6 +152,7 @@ const Radar = {
148
152
  acceptEvent,
149
153
  rejectEvent,
150
154
  startTrip,
155
+ updateTrip,
151
156
  completeTrip,
152
157
  cancelTrip,
153
158
  getContext,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "react-native-radar",
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
- "homepage": "https://radar.io",
4
+ "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.1.5",
6
+ "version": "3.2.1",
7
7
  "main": "js/index.js",
8
8
  "files": [
9
9
  "android",
@@ -56,5 +56,8 @@
56
56
  "repository": {
57
57
  "type": "git",
58
58
  "url": "https://github.com/radarlabs/react-native-radar.git"
59
+ },
60
+ "dependencies": {
61
+ "@react-native-community/netinfo": "^7.1.3"
59
62
  }
60
63
  }
@@ -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.1.10"
18
+ s.dependency "RadarSDK", "~> 3.2.3"
19
19
  end