@sentiance-react-native/core 6.7.1 → 6.8.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ sentiance_sdk_env_var_version = ENV["SENTIANCE_RN_IOS_SDK_VERSION"]
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = "RNSentianceCore"
8
- s.version = "6.7.1"
8
+ s.version = "6.8.0-alpha.2"
9
9
  s.summary = "RNSentianceCore"
10
10
  s.description = <<-DESC
11
11
  RNSentianceCore
@@ -44,8 +44,26 @@ public abstract class AbstractSentianceModule extends ReactContextBaseJavaModule
44
44
 
45
45
  }
46
46
 
47
+ /**
48
+ * This binding is invoked when the Sentiance SDK's Javascript APIs attempt to unregister listeners for a specific event.
49
+ *
50
+ * @param eventName the name of the event from which the app wants to unsubscribe.
51
+ * @param subscriptionId The identifier of the Javascript subscription that was created following
52
+ * an attempt to add a listener for the provided event name.
53
+ * @param promise that resolves once the native SDK listener(s) has/have been unset.
54
+ */
47
55
  protected abstract void removeNativeListener(String eventName, int subscriptionId, Promise promise);
48
56
 
57
+ /**
58
+ * This binding is invoked when the Sentiance SDK's Javascript APIs attempt to register listeners for a specific event.
59
+ *
60
+ * @param eventName the name of the event of which the app wants to be notified.
61
+ * @param subscriptionId The identifier of the Javascript subscription that was created following
62
+ * an attempt to add a listener for the provided event name. By default,
63
+ * React Native supports adding multiple listeners for the same event,
64
+ * but most of the Sentiance native SDKs don't.
65
+ * @param promise that resolves once the native SDK listener(s) has/have been set.
66
+ */
49
67
  protected abstract void addNativeListener(String eventName, int subscriptionId, Promise promise);
50
68
 
51
69
  protected abstract void addListener(String eventName);
@@ -55,5 +55,8 @@ typedef NS_ENUM(NSInteger, UIBackgroundRefreshStatus);
55
55
  - (NSArray *)convertCallWhileMovingEvents:(NSArray<SENTCallWhileMovingEvent*> *)callWhileMovingEvents;
56
56
  - (NSArray *)convertSpeedingEvents:(NSArray<SENTSpeedingEvent*> *)speedingEvents;
57
57
  - (NSMutableDictionary*)convertEvent:(SENTTimelineEvent*)event;
58
+ - (NSError *)convertSmartGeofencesRefreshError:(SENTSmartGeofencesRefreshError *)refreshError;
59
+ - (NSString *)stringifySmartGeofencesDetectionMode:(SENTSmartGeofenceDetectionMode)detectionMode;
60
+ - (NSDictionary*)convertSmartGeofenceEvent:(SENTSmartGeofenceEvent*)event;
58
61
 
59
62
  @end
@@ -10,6 +10,9 @@
10
10
  @import UIKit.UIApplication;
11
11
  @import CoreLocation;
12
12
 
13
+ static NSString * const SmartGeofencesErrorDomain = @"com.sentiance.SmartGeofencesModule";
14
+
15
+
13
16
  @interface RNSentianceCore (Private)
14
17
 
15
18
  - (NSString*)convertTimelineEventTypeToString:(SENTTimelineEventType)type;
@@ -464,14 +467,14 @@
464
467
 
465
468
  - (NSArray*)convertSegmentAttributes:(NSArray<SENTAttribute *>*)attributes {
466
469
  NSMutableArray *attributeArray = [[NSMutableArray alloc] init];
467
-
470
+
468
471
  for (SENTAttribute* attribute in attributes) {
469
472
  NSMutableDictionary *attributeDict = [[NSMutableDictionary alloc] init];
470
473
  attributeDict[@"name"] = attribute.name;
471
474
  attributeDict[@"value"] = @(attribute.value);
472
475
  [attributeArray addObject:attributeDict];
473
476
  }
474
-
477
+
475
478
  return attributeArray;
476
479
  }
477
480
 
@@ -1243,4 +1246,97 @@
1243
1246
  return dict;
1244
1247
  }
1245
1248
 
1249
+ - (NSError *)convertSmartGeofencesRefreshError:(SENTSmartGeofencesRefreshError *)refreshError {
1250
+ NSString *reason;
1251
+ NSString *details = refreshError.details == nil ? @"": refreshError.details;
1252
+
1253
+ switch (refreshError.failureReason) {
1254
+ case SENTSmartGeofencesRefreshFailureReasonNetworkUsageRestricted:
1255
+ reason = @"NETWORK_USAGE_RESTRICTED";
1256
+ break;
1257
+ case SENTSmartGeofencesRefreshFailureReasonNetworkError:
1258
+ reason = @"NETWORK_ERROR";
1259
+ break;
1260
+ case SENTSmartGeofencesRefreshFailureReasonServerError:
1261
+ reason = @"SERVER_ERROR";
1262
+ break;
1263
+ case SENTSmartGeofencesRefreshFailureReasonTooManyFrequentCalls:
1264
+ reason = @"TOO_MANY_FREQUENT_CALLS";
1265
+ break;
1266
+ case SENTSmartGeofencesRefreshFailureReasonFeatureNotEnabled:
1267
+ reason = @"FEATURE_NOT_ENABLED";
1268
+ break;
1269
+ case SENTSmartGeofencesRefreshFailureReasonUnexpectedError:
1270
+ default:
1271
+ reason = @"UNEXPECTED_ERROR";
1272
+ break;
1273
+ }
1274
+
1275
+ NSMutableDictionary *errorInfo = [NSMutableDictionary dictionary];
1276
+ errorInfo[@"reason"] = reason;
1277
+ errorInfo[@"details"] = details;
1278
+
1279
+ NSError *error = [NSError errorWithDomain:SmartGeofencesErrorDomain
1280
+ code:0
1281
+ userInfo:errorInfo];
1282
+
1283
+ return error;
1284
+ }
1285
+
1286
+ - (NSString *)stringifySmartGeofencesDetectionMode:(SENTSmartGeofenceDetectionMode)detectionMode {
1287
+ switch (detectionMode) {
1288
+ case SENTSmartGeofenceDetectionModeBackground:
1289
+ return @"BACKGROUND";
1290
+ case SENTSmartGeofenceDetectionModeForeground:
1291
+ return @"FOREGROUND";
1292
+ case SENTSmartGeofenceDetectionModeDisabled:
1293
+ return @"DISABLED";
1294
+ case SENTSmartGeofenceDetectionModeFeatureNotEnabled:
1295
+ default:
1296
+ return @"FEATURE_NOT_ENABLED";
1297
+ }
1298
+ }
1299
+
1300
+ - (NSDictionary*)convertSmartGeofenceEvent:(SENTSmartGeofenceEvent*)event {
1301
+ NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
1302
+
1303
+ dict[@"timestamp"] = @((long) ([event.eventDate timeIntervalSince1970] * 1000));
1304
+ dict[@"triggeringLocation"] = [self convertCllocation:event.triggeringLocation];
1305
+
1306
+ NSString *eventType;
1307
+ switch(event.eventType) {
1308
+ case SENTSmartGeofenceEventTypeEntry:
1309
+ eventType = @"ENTRY";
1310
+ break;
1311
+ case SENTSmartGeofenceEventTypeExit:
1312
+ eventType = @"EXIT";
1313
+ break;
1314
+ }
1315
+
1316
+ dict[@"eventType"] = eventType;
1317
+ dict[@"geofences"] = [self convertSmartGeofences:event.geofences];
1318
+
1319
+ return dict;
1320
+ }
1321
+
1322
+ - (NSArray<NSDictionary<NSString *, NSNumber *> *> *)convertSmartGeofences:(NSArray<SENTSmartGeofence*> *)smartGeofences {
1323
+ NSMutableArray <NSDictionary*> *array = [[NSMutableArray alloc] init];
1324
+ for (SENTSmartGeofence *smartGeofence in smartGeofences) {
1325
+ [array addObject:[self convertSmartGeofence:smartGeofence]];
1326
+ }
1327
+ return array;
1328
+ }
1329
+
1330
+ - (NSDictionary*)convertSmartGeofence:(SENTSmartGeofence*)smartGeofence {
1331
+ NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
1332
+
1333
+ dict[@"sentianceId"] = smartGeofence.sentianceId;
1334
+ dict[@"latitude"] = @(smartGeofence.latitude);
1335
+ dict[@"longitude"] = @(smartGeofence.longitude);
1336
+ dict[@"radius"] = @(smartGeofence.radius);
1337
+ dict[@"externalId"] = smartGeofence.externalId;
1338
+
1339
+ return dict;
1340
+ }
1341
+
1246
1342
  @end
@@ -14,8 +14,9 @@ static NSString * _Nonnull const VehicleCrashDiagnosticEvent = @"SENTIANCE_VEHIC
14
14
  static NSString * _Nonnull const UserContextUpdateEvent = @"SENTIANCE_USER_CONTEXT_UPDATE_EVENT";
15
15
  static NSString * _Nonnull const DrivingInsightsReadyEvent = @"SENTIANCE_DRIVING_INSIGHTS_READY_EVENT";
16
16
  static NSString * _Nonnull const TimelineUpdateEvent = @"SENTIANCE_TIMELINE_UPDATE_EVENT";
17
+ static NSString * _Nonnull const SmartGeofenceEvent = @"SENTIANCE_SMART_GEOFENCE_EVENT";
17
18
 
18
- @interface RNSentianceCore : RCTEventEmitter <RCTBridgeModule, SENTUserContextDelegate, SENTDrivingInsightsReadyDelegate, SENTEventTimelineDelegate>
19
+ @interface RNSentianceCore : RCTEventEmitter <RCTBridgeModule, SENTUserContextDelegate, SENTDrivingInsightsReadyDelegate, SENTEventTimelineDelegate, SENTSmartGeofenceEventDelegate>
19
20
  typedef void (^SdkStatusHandler)(SENTSDKStatus * _Nonnull status);
20
21
  - (SENTUserLinker _Nonnull ) getUserLinker;
21
22
  - (SdkStatusHandler _Nonnull) getSdkStatusUpdateHandler;
@@ -35,7 +35,7 @@ RCT_EXPORT_MODULE(SentianceCore)
35
35
 
36
36
  - (NSArray<NSString *> *)supportedEvents
37
37
  {
38
- return @[SdkStatusUpdateEvent, TripTimeoutEvent, UserLinkEvent, UserActivityUpdateEvent, VehicleCrashEvent, VehicleCrashDiagnosticEvent, UserLinkEvent, UserContextUpdateEvent, DrivingInsightsReadyEvent, TimelineUpdateEvent];
38
+ return @[SdkStatusUpdateEvent, TripTimeoutEvent, UserLinkEvent, UserActivityUpdateEvent, VehicleCrashEvent, VehicleCrashDiagnosticEvent, UserLinkEvent, UserContextUpdateEvent, DrivingInsightsReadyEvent, TimelineUpdateEvent, SmartGeofenceEvent];
39
39
  }
40
40
 
41
41
  // Will be called when this module's first listener is added.
@@ -62,6 +62,10 @@ RCT_EXPORT_MODULE(SentianceCore)
62
62
  [self sendEventWithName:TimelineUpdateEvent body:[self convertEvent:event]];
63
63
  }
64
64
 
65
+ - (void)onSmartGeofenceEvent:(SENTSmartGeofenceEvent * _Nonnull)smartGeofenceEvent {
66
+ [self sendEventWithName:SmartGeofenceEvent body:[self convertSmartGeofenceEvent:smartGeofenceEvent]];
67
+ }
68
+
65
69
  - (instancetype)init
66
70
  {
67
71
  self = [super init];
@@ -80,6 +84,12 @@ RCT_EXPORT_MODULE(SentianceCore)
80
84
  [[Sentiance sharedInstance] setEventTimelineDelegate:nil];
81
85
  } subscriptionType:SENTSubscriptionTypeSingle];
82
86
 
87
+ [_subscriptionsManager addSupportedSubscriptionForEventType:SmartGeofenceEvent nativeSubscribeLogic:^{
88
+ [[Sentiance sharedInstance] setSmartGeofenceEventsDelegate:weakSelf];
89
+ } nativeUnsubscribeLogic:^{
90
+ [[Sentiance sharedInstance] setSmartGeofenceEventsDelegate:nil];
91
+ } subscriptionType:SENTSubscriptionTypeSingle];
92
+
83
93
  return self;
84
94
  }
85
95
 
@@ -1161,6 +1171,33 @@ RCT_EXPORT_METHOD(isAllowedToUseMobileData:(RCTPromiseResolveBlock)resolve rejec
1161
1171
  resolve(@(Sentiance.sharedInstance.isAllowedToUseMobileData));
1162
1172
  }
1163
1173
 
1174
+ RCT_EXPORT_METHOD(refreshGeofences:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
1175
+ REJECT_IF_SDK_NOT_INITIALIZED(reject);
1176
+
1177
+ @try {
1178
+ [[Sentiance sharedInstance] refreshSmartGeofencesWithCompletionHandler:^(SENTSmartGeofencesRefreshResult * _Nullable result, SENTSmartGeofencesRefreshError * _Nullable error) {
1179
+ if (error != nil) {
1180
+ reject(ESDKSmartGeofencesRefreshError, @"Failed to refresh smart geofences", [self convertSmartGeofencesRefreshError:error]);
1181
+ }
1182
+ else {
1183
+ resolve(nil);
1184
+ }
1185
+ }];
1186
+ } @catch (NSException *e) {
1187
+ reject(e.name, e.reason, nil);
1188
+ }
1189
+ }
1190
+
1191
+ RCT_EXPORT_METHOD(getDetectionMode:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
1192
+ REJECT_IF_SDK_NOT_INITIALIZED(reject);
1193
+
1194
+ @try {
1195
+ resolve([self stringifySmartGeofencesDetectionMode:Sentiance.sharedInstance.smartGeofenceDetectionMode]);
1196
+ } @catch (NSException *e) {
1197
+ reject(e.name, e.reason, nil);
1198
+ }
1199
+ }
1200
+
1164
1201
  - (void)didUpdateUserContext:(SENTUserContext *)userContext
1165
1202
  forCriteriaMask:(SENTUserContextUpdateCriteria)criteriaMask {
1166
1203
  NSDictionary *dict = @{
@@ -18,3 +18,4 @@ extern NSString * const ESDKUserLinkAuthCodeError;
18
18
  extern NSString * const ESDKCreateUserError;
19
19
  extern NSString * const ESDKResetError;
20
20
  extern NSString * const ESDKRequestUserContextError;
21
+ extern NSString * const ESDKSmartGeofencesRefreshError;
@@ -20,3 +20,4 @@ NSString * const ESDKUserLinkAuthCodeError = @"E_SDK_USER_LINK_AUTH_CODE_ERROR";
20
20
  NSString * const ESDKCreateUserError = @"E_SDK_CREATE_USER_ERROR";
21
21
  NSString * const ESDKResetError = @"E_SDK_RESET_ERROR";
22
22
  NSString * const ESDKRequestUserContextError = @"E_SDK_REQUEST_USER_CONTEXT_ERROR";
23
+ NSString * const ESDKSmartGeofencesRefreshError = @"E_SDK_SMART_GEOFENCES_REFRESH_ERROR";
package/lib/index.d.ts CHANGED
@@ -61,6 +61,7 @@ declare module "@sentiance-react-native/core" {
61
61
  }
62
62
 
63
63
  export interface Location {
64
+ timestamp?: number; // marked optional to maintain compatibility, but is always present
64
65
  latitude: number;
65
66
  longitude: number;
66
67
  accuracy?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentiance-react-native/core",
3
- "version": "6.7.1",
3
+ "version": "6.8.0-alpha.2",
4
4
  "description": "The Sentiance Core library",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -29,10 +29,10 @@
29
29
  "targetSdk": 31,
30
30
  "compileSdk": 31,
31
31
  "buildTools": "30.0.3",
32
- "sentiance": "6.7.+"
32
+ "sentiance": "6.8.0-beta1"
33
33
  },
34
34
  "ios": {
35
- "sentiance": "~> 6.7.0"
35
+ "sentiance": "6.8.0-beta1"
36
36
  }
37
37
  }
38
38
  }