react-native-visit-rn-sdk 3.0.12 → 3.0.14
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 +18 -3
- package/ios/VisitRnSdkViewManager.h +2 -0
- package/ios/VisitRnSdkViewManager.m +99 -112
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
### **Instructions for configuring your Android Project**
|
|
2
2
|
|
|
3
3
|
* Install Visit React Native Plugin
|
|
4
|
-
`npm install react-native-visit-rn-sdk@3.0.
|
|
4
|
+
`npm install react-native-visit-rn-sdk@3.0.14`
|
|
5
5
|
* Install these transitive plugins that Visit Plugin requires internally:
|
|
6
6
|
`npm install react-native-device-info`
|
|
7
7
|
`npm install https://github.com/sashko9807/react-native-location-enabler`
|
|
@@ -42,7 +42,7 @@ android {
|
|
|
42
42
|
|
|
43
43
|
### **Instructions for configuring Plugin in iOS project**
|
|
44
44
|
|
|
45
|
-
* Add the plugin `npm install react-native-visit-rn-sdk@3.0.
|
|
45
|
+
* Add the plugin `npm install react-native-visit-rn-sdk@3.0.14 && npx pod-install`
|
|
46
46
|
* Install pods(for M1 processors running build on `x86_64` hardware)
|
|
47
47
|
|
|
48
48
|
`arch -x86_64 pod install`
|
|
@@ -86,7 +86,7 @@ To see the full usage code for getting Health Connect/HealthKit connection statu
|
|
|
86
86
|
|
|
87
87
|
## **Health Connect Connection Flow (Android)**
|
|
88
88
|
|
|
89
|
-
Version `3.0.
|
|
89
|
+
Version `3.0.14` uses AndroidSDK `v3.13` and routes the PWA's Health Connect request according to the Health Connect installation status and the device's native step-tracking capability.
|
|
90
90
|
|
|
91
91
|
The maintained RN 3.x release is also available through its npm dist-tag:
|
|
92
92
|
|
|
@@ -197,6 +197,21 @@ Set `isLoggingEnabled={true}` on `VisitRnSdkView` to log the status, capability
|
|
|
197
197
|
|
|
198
198
|
## **RN 3.x Release Notes**
|
|
199
199
|
|
|
200
|
+
### **3.0.14**
|
|
201
|
+
|
|
202
|
+
* Request read-only HealthKit access for step data on iOS without requesting write permission.
|
|
203
|
+
* Determine HealthKit connection status without writing and deleting a probe step sample.
|
|
204
|
+
* Keep the existing JavaScript APIs and callback signatures unchanged.
|
|
205
|
+
|
|
206
|
+
### **3.0.13**
|
|
207
|
+
|
|
208
|
+
* Add iOS compatibility methods for `getTodaySleepMinutes()` and `getTodayCalorieCount()` that resolve to `0`.
|
|
209
|
+
* Keep the existing JavaScript APIs and callback signatures unchanged.
|
|
210
|
+
|
|
211
|
+
### **3.0.12**
|
|
212
|
+
|
|
213
|
+
* Rely on the PWA's `GET_HEALTH_CONNECT_STATUS` request instead of automatically refreshing Health Connect status whenever the Android app returns to the foreground.
|
|
214
|
+
|
|
200
215
|
### **3.0.11**
|
|
201
216
|
|
|
202
217
|
* Upgrade AndroidSDK to `v3.13`.
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
- (void)getHealthKitStatus:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
20
20
|
- (void)requestHealthKitAuthorization:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
21
21
|
- (void)getTodayStepCount:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
22
|
+
- (void)getTodaySleepMinutes:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
23
|
+
- (void)getTodayCalorieCount:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
22
24
|
- (void)triggerManualSync:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject;
|
|
23
25
|
|
|
24
26
|
@end
|
|
@@ -313,10 +313,9 @@ RCT_REMAP_METHOD(multiply,
|
|
|
313
313
|
// If our device doesn't support HealthKit -> return.
|
|
314
314
|
return;
|
|
315
315
|
}
|
|
316
|
-
NSArray *writeTypes = @[[HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
|
|
317
316
|
NSArray *readTypes = @[[HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
|
|
318
|
-
|
|
319
|
-
[[VisitRnSdkViewManager sharedManager] requestAuthorizationToShareTypes:
|
|
317
|
+
|
|
318
|
+
[[VisitRnSdkViewManager sharedManager] requestAuthorizationToShareTypes:nil readTypes:[NSSet setWithArray:readTypes]
|
|
320
319
|
completion:^(BOOL success, NSError *error) {
|
|
321
320
|
NSLog(@"requestAuthorizationToShareTypes executed");
|
|
322
321
|
[self canAccessHealthKit:^(BOOL value){
|
|
@@ -352,29 +351,24 @@ RCT_REMAP_METHOD(multiply,
|
|
|
352
351
|
}
|
|
353
352
|
|
|
354
353
|
-(void) canAccessHealthKit: (void(^)(BOOL))callback {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
callback(YES);
|
|
374
|
-
}
|
|
375
|
-
}];
|
|
376
|
-
}
|
|
377
|
-
}];
|
|
354
|
+
if (![HKHealthStore isHealthDataAvailable]) {
|
|
355
|
+
callback(NO);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
NSSet *readTypes = [NSSet setWithObject:
|
|
360
|
+
[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
|
|
361
|
+
|
|
362
|
+
[[VisitRnSdkViewManager sharedManager]
|
|
363
|
+
getRequestStatusForAuthorizationToShareTypes:[NSSet set]
|
|
364
|
+
readTypes:readTypes
|
|
365
|
+
completion:^(HKAuthorizationRequestStatus status,
|
|
366
|
+
NSError *error) {
|
|
367
|
+
if (error) {
|
|
368
|
+
NSLog(@"canAccessHealthKit request status error: %@", error.localizedDescription);
|
|
369
|
+
}
|
|
370
|
+
callback(status == HKAuthorizationRequestStatusUnnecessary);
|
|
371
|
+
}];
|
|
378
372
|
}
|
|
379
373
|
|
|
380
374
|
-(void) evaluateJavascript:(NSArray *) data type:(NSString *) type frequency:(NSString *) frequency activityTime:(NSString *) activityTime callback:(void(^)(NSArray*))callback{
|
|
@@ -587,49 +581,43 @@ RCT_EXPORT_METHOD(connectToAppleHealth:(RCTResponseSenderBlock)callback)
|
|
|
587
581
|
return;
|
|
588
582
|
}
|
|
589
583
|
|
|
590
|
-
HKObjectType *stepType =
|
|
591
|
-
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
|
|
592
|
-
HKAuthorizationStatus preStatus =
|
|
593
|
-
[[VisitRnSdkViewManager sharedManager] authorizationStatusForType:stepType];
|
|
594
|
-
|
|
595
|
-
// Match Android: report DENIED to JS and let the caller decide whether to
|
|
596
|
-
// prompt the user (via Alert) to open the Health app. Do NOT open Health
|
|
597
|
-
// ourselves — the JS side calls openAppleHealthApp on user confirmation.
|
|
598
|
-
if (preStatus == HKAuthorizationStatusSharingDenied) {
|
|
599
|
-
callback(@[@{@"authStatus": @"DENIED"}]);
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
NSSet *writeTypes =
|
|
604
|
-
[NSSet setWithObject:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
|
|
605
584
|
NSSet *readTypes = [NSSet setWithArray:@[
|
|
606
585
|
[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount],
|
|
607
586
|
]];
|
|
608
587
|
|
|
609
588
|
__weak typeof(self) weakSelf = self;
|
|
610
589
|
[[VisitRnSdkViewManager sharedManager]
|
|
611
|
-
requestAuthorizationToShareTypes:
|
|
590
|
+
requestAuthorizationToShareTypes:nil
|
|
612
591
|
readTypes:readTypes
|
|
613
592
|
completion:^(BOOL success, NSError *error) {
|
|
614
593
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
615
594
|
if (!strongSelf) { return; }
|
|
616
595
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if (postStatus == HKAuthorizationStatusSharingDenied) {
|
|
596
|
+
if (!success) {
|
|
597
|
+
NSLog(@"connectToAppleHealth authorization failed: %@", error.localizedDescription);
|
|
598
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
622
599
|
callback(@[@{@"authStatus": @"DENIED"}]);
|
|
623
|
-
|
|
624
|
-
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
625
603
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
604
|
+
[strongSelf canAccessHealthKit:^(BOOL resolved) {
|
|
605
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
606
|
+
if (!resolved) {
|
|
607
|
+
// Sheet was never answered, so treat it as not granted and
|
|
608
|
+
// let JS offer the Apple Health deep link.
|
|
609
|
+
callback(@[@{@"authStatus": @"DENIED"}]);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
[strongSelf onHealthKitPermissionGranted:^(NSDictionary *data) {
|
|
614
|
+
NSMutableDictionary *out =
|
|
615
|
+
[NSMutableDictionary dictionaryWithDictionary:data ?: @{}];
|
|
616
|
+
out[@"authStatus"] = @"GRANTED";
|
|
617
|
+
callback(@[out]);
|
|
618
|
+
}];
|
|
619
|
+
});
|
|
620
|
+
}];
|
|
633
621
|
}];
|
|
634
622
|
}
|
|
635
623
|
|
|
@@ -1029,42 +1017,36 @@ RCT_REMAP_METHOD(getHealthKitStatus,
|
|
|
1029
1017
|
return;
|
|
1030
1018
|
}
|
|
1031
1019
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1020
|
+
// Was gated on HKAuthorizationStatusSharingAuthorized, i.e. *write*
|
|
1021
|
+
// authorization, which this read-only SDK no longer requests. Now gated on
|
|
1022
|
+
// whether the permission sheet has been answered.
|
|
1023
|
+
[self canAccessHealthKit:^(BOOL resolved) {
|
|
1024
|
+
if (!resolved) {
|
|
1025
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1026
|
+
resolve(@(NO)); // HealthKit access not granted
|
|
1027
|
+
});
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1039
1030
|
|
|
1040
|
-
|
|
1041
|
-
dispatch_group_enter(syncDataGroup);
|
|
1031
|
+
NSInteger days = 1;
|
|
1042
1032
|
[self fetchSteps:@"custom"
|
|
1043
1033
|
endDate:[NSDate date]
|
|
1044
1034
|
days:days
|
|
1045
1035
|
callback:^(NSArray *data) {
|
|
1046
1036
|
NSLog(@"Fetched steps data: %@", data);
|
|
1047
|
-
stepsData = [data objectAtIndex:0];
|
|
1048
|
-
|
|
1037
|
+
NSArray *stepsData = [data count] > 0 ? [data objectAtIndex:0] : nil;
|
|
1038
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1039
|
+
if (stepsData) {
|
|
1040
|
+
resolve(@{@"steps": stepsData});
|
|
1041
|
+
} else {
|
|
1042
|
+
NSError *error = [NSError errorWithDomain:@"HealthKit"
|
|
1043
|
+
code:500
|
|
1044
|
+
userInfo:@{NSLocalizedDescriptionKey: @"Failed to fetch step data"}];
|
|
1045
|
+
reject(@"fetch_error", @"Error fetching step data", error);
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1049
1048
|
}];
|
|
1050
|
-
|
|
1051
|
-
// Wait for the fetch to complete
|
|
1052
|
-
dispatch_group_notify(syncDataGroup, dispatch_get_main_queue(), ^{
|
|
1053
|
-
if (stepsData) {
|
|
1054
|
-
NSDictionary *result = @{
|
|
1055
|
-
@"steps": stepsData,
|
|
1056
|
-
};
|
|
1057
|
-
resolve(result);
|
|
1058
|
-
} else {
|
|
1059
|
-
NSError *error = [NSError errorWithDomain:@"HealthKit"
|
|
1060
|
-
code:500
|
|
1061
|
-
userInfo:@{NSLocalizedDescriptionKey: @"Failed to fetch step data"}];
|
|
1062
|
-
reject(@"fetch_error", @"Error fetching step data", error);
|
|
1063
|
-
}
|
|
1064
|
-
});
|
|
1065
|
-
} else {
|
|
1066
|
-
resolve(@(NO)); // HealthKit access not granted
|
|
1067
|
-
}
|
|
1049
|
+
}];
|
|
1068
1050
|
}
|
|
1069
1051
|
|
|
1070
1052
|
RCT_REMAP_METHOD(requestHealthKitAuthorization,
|
|
@@ -1076,44 +1058,33 @@ RCT_REMAP_METHOD(requestHealthKitAuthorization,
|
|
|
1076
1058
|
return;
|
|
1077
1059
|
}
|
|
1078
1060
|
|
|
1079
|
-
NSSet *writeTypes =
|
|
1080
|
-
[NSSet setWithObject:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]];
|
|
1081
1061
|
NSMutableSet *readTypes = [NSMutableSet setWithArray:@[
|
|
1082
1062
|
[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount],
|
|
1083
1063
|
]];
|
|
1084
1064
|
|
|
1065
|
+
__weak typeof(self) weakSelf = self;
|
|
1085
1066
|
[[VisitRnSdkViewManager sharedManager]
|
|
1086
|
-
requestAuthorizationToShareTypes:
|
|
1067
|
+
requestAuthorizationToShareTypes:nil
|
|
1087
1068
|
readTypes:readTypes
|
|
1088
1069
|
completion:^(BOOL success, NSError *error) {
|
|
1089
|
-
|
|
1090
|
-
|
|
1070
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
1071
|
+
if (!success || !strongSelf) {
|
|
1072
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1091
1073
|
reject(@"AUTHORIZATION_FAILED",
|
|
1092
1074
|
error.localizedDescription ?: @"HealthKit authorization failed",
|
|
1093
1075
|
error);
|
|
1094
|
-
|
|
1095
|
-
|
|
1076
|
+
});
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1096
1079
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
statusString = @"GRANTED";
|
|
1106
|
-
break;
|
|
1107
|
-
case HKAuthorizationStatusSharingDenied:
|
|
1108
|
-
statusString = @"DENIED";
|
|
1109
|
-
break;
|
|
1110
|
-
case HKAuthorizationStatusNotDetermined:
|
|
1111
|
-
default:
|
|
1112
|
-
statusString = @"NOT_DETERMINED";
|
|
1113
|
-
break;
|
|
1114
|
-
}
|
|
1115
|
-
resolve(statusString);
|
|
1116
|
-
});
|
|
1080
|
+
// Resolves GRANTED once the sheet has been answered. DENIED is not
|
|
1081
|
+
// reachable for a read-only app: HealthKit reports read authorization
|
|
1082
|
+
// to no one, so a denial is indistinguishable from having no step data.
|
|
1083
|
+
[strongSelf canAccessHealthKit:^(BOOL resolved) {
|
|
1084
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1085
|
+
resolve(resolved ? @"GRANTED" : @"NOT_DETERMINED");
|
|
1086
|
+
});
|
|
1087
|
+
}];
|
|
1117
1088
|
}];
|
|
1118
1089
|
}
|
|
1119
1090
|
|
|
@@ -1158,6 +1129,22 @@ RCT_REMAP_METHOD(getTodayStepCount,
|
|
|
1158
1129
|
[[VisitRnSdkViewManager sharedManager] executeQuery:query];
|
|
1159
1130
|
}
|
|
1160
1131
|
|
|
1132
|
+
// Compatibility stub: always resolves 0.
|
|
1133
|
+
RCT_REMAP_METHOD(getTodaySleepMinutes,
|
|
1134
|
+
getTodaySleepMinutesWithResolver:(RCTPromiseResolveBlock)resolve
|
|
1135
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
1136
|
+
{
|
|
1137
|
+
resolve(@0);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// Compatibility stub: always resolves 0.
|
|
1141
|
+
RCT_REMAP_METHOD(getTodayCalorieCount,
|
|
1142
|
+
getTodayCalorieCountWithResolver:(RCTPromiseResolveBlock)resolve
|
|
1143
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
1144
|
+
{
|
|
1145
|
+
resolve(@0);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1161
1148
|
RCT_REMAP_METHOD(triggerManualSync,
|
|
1162
1149
|
triggerManualSyncWithResolver:(RCTPromiseResolveBlock)resolve
|
|
1163
1150
|
rejecter:(RCTPromiseRejectBlock)reject)
|