react-native-rook-sdk 0.6.2 → 1.0.0-rc.0
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/build.gradle +1 -1
- package/android/src/main/AndroidManifestNew.xml +0 -8
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +94 -580
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +17 -1
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +54 -0
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +53 -0
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +108 -0
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +160 -0
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +105 -0
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +497 -0
- package/android/src/main/java/com/rooksdk/utils/DatasourcesUtils.kt +49 -0
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +64 -0
- package/android/src/main/java/com/rooksdk/utils/RookDateTime.kt +20 -0
- package/ios/RookSdk.mm +393 -42
- package/lib/commonjs/context/RookSyncGateContext.js +12 -0
- package/lib/commonjs/context/RookSyncGateContext.js.map +1 -1
- package/lib/commonjs/context/RookSyncGateProvider.js +14 -6
- package/lib/commonjs/context/RookSyncGateProvider.js.map +1 -1
- package/lib/commonjs/context/RookSyncGateReducer.js +15 -0
- package/lib/commonjs/context/RookSyncGateReducer.js.map +1 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +26 -38
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +24 -10
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js +22 -4
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js.map +1 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +32 -16
- package/lib/commonjs/hooks/useRookConfiguration.js.map +1 -1
- package/lib/commonjs/hooks/useRookDataSources.js +30 -5
- package/lib/commonjs/hooks/useRookDataSources.js.map +1 -1
- package/lib/commonjs/hooks/useRookEvents.js +61 -57
- package/lib/commonjs/hooks/useRookEvents.js.map +1 -1
- package/lib/commonjs/hooks/useRookPermissions.js +79 -37
- package/lib/commonjs/hooks/useRookPermissions.js.map +1 -1
- package/lib/commonjs/hooks/useRookSummaries.js +23 -29
- package/lib/commonjs/hooks/useRookSummaries.js.map +1 -1
- package/lib/commonjs/index.js +20 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/hook/useRookAutoSync.js +133 -27
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +2 -0
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +1 -0
- package/lib/commonjs/types/PermissionsType.js +2 -0
- package/lib/commonjs/types/PermissionsType.js.map +1 -0
- package/lib/commonjs/utils/getNativeModule.js +29 -0
- package/lib/commonjs/utils/getNativeModule.js.map +1 -0
- package/lib/commonjs/utils/getRookModule.js +7 -0
- package/lib/commonjs/utils/getRookModule.js.map +1 -1
- package/lib/commonjs/utils/isModuleReady.js +6 -0
- package/lib/commonjs/utils/isModuleReady.js.map +1 -1
- package/lib/commonjs/utils/isValidDate.js +6 -0
- package/lib/commonjs/utils/isValidDate.js.map +1 -1
- package/lib/commonjs/utils/nativeModules.js +19 -0
- package/lib/commonjs/utils/nativeModules.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +12 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +10 -2
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +15 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +14 -26
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +15 -2
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealthVariables.js +20 -2
- package/lib/module/hooks/useRookAppleHealthVariables.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +18 -3
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookDataSources.js +27 -3
- package/lib/module/hooks/useRookDataSources.js.map +1 -1
- package/lib/module/hooks/useRookEvents.js +32 -28
- package/lib/module/hooks/useRookEvents.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +63 -22
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSummaries.js +16 -22
- package/lib/module/hooks/useRookSummaries.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/hook/useRookAutoSync.js +133 -28
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/types/sendMessageBroadcast.js +2 -0
- package/lib/module/modules/types/sendMessageBroadcast.js.map +1 -0
- package/lib/module/types/PermissionsType.js +2 -0
- package/lib/module/types/PermissionsType.js.map +1 -0
- package/lib/module/utils/getNativeModule.js +23 -0
- package/lib/module/utils/getNativeModule.js.map +1 -0
- package/lib/module/utils/getRookModule.js +8 -0
- package/lib/module/utils/getRookModule.js.map +1 -1
- package/lib/module/utils/isModuleReady.js +6 -0
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isValidDate.js +6 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/module/utils/nativeModules.js +13 -0
- package/lib/module/utils/nativeModules.js.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts +7 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts +15 -0
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts +6 -2
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts +9 -0
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +7 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts +8 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts +9 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +16 -3
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSummaries.d.ts +6 -6
- package/lib/typescript/src/hooks/useRookSummaries.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts +18 -1
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/modules/types/sendMessageBroadcast.d.ts +6 -0
- package/lib/typescript/src/modules/types/sendMessageBroadcast.d.ts.map +1 -0
- package/lib/typescript/src/types/DataSource.d.ts +1 -0
- package/lib/typescript/src/types/DataSource.d.ts.map +1 -1
- package/lib/typescript/src/types/PermissionsType.d.ts +6 -0
- package/lib/typescript/src/types/PermissionsType.d.ts.map +1 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts +10 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/getRookModule.d.ts +7 -0
- package/lib/typescript/src/utils/getRookModule.d.ts.map +1 -1
- package/lib/typescript/src/utils/isModuleReady.d.ts +6 -0
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts +6 -0
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +14 -0
- package/lib/typescript/src/utils/nativeModules.d.ts.map +1 -0
- package/package.json +1 -1
- package/react-native-rook-sdk.podspec +1 -1
- package/android/src/main/java/com/rooksdk/HealthConnectPermissionsActivity.kt +0 -40
- package/android/src/main/java/com/rooksdk/RookDateTime.kt +0 -12
- package/android/src/main/res/layout/activity_health_connect_permissions.xml +0 -15
- package/lib/commonjs/utils/index.js +0 -69
- package/lib/commonjs/utils/index.js.map +0 -1
- package/lib/module/utils/index.js +0 -9
- package/lib/module/utils/index.js.map +0 -1
- package/lib/typescript/src/utils/index.d.ts +0 -9
- package/lib/typescript/src/utils/index.d.ts.map +0 -1
package/ios/RookSdk.mm
CHANGED
|
@@ -11,6 +11,10 @@ NSString *convertToString(id value) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// The above code is a function that takes a string representing a date in the
|
|
15
|
+
// format "yyyy-MM-dd" as input. It creates an instance of NSDateFormatter, sets the date format to
|
|
16
|
+
// "yyyy-MM-dd", and then uses the date formatter to convert the input string into an NSDate object
|
|
17
|
+
// representing the parsed date. Finally, it returns the parsed NSDate object.
|
|
14
18
|
NSDate *parseDateFromString(NSString * dateString) {
|
|
15
19
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
16
20
|
|
|
@@ -21,6 +25,11 @@ NSDate *parseDateFromString(NSString * dateString) {
|
|
|
21
25
|
return date;
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
// A function that takes an NSException object as input and creates an
|
|
29
|
+
// NSError object based on the exception information. It creates a dictionary with localized
|
|
30
|
+
// description and failure reason keys using the exception's name and reason properties. Then, it
|
|
31
|
+
// creates an NSError object with a custom domain, error code, and the dictionary of error information,
|
|
32
|
+
// and returns it.
|
|
24
33
|
NSError *errorFromException(NSException *exception) {
|
|
25
34
|
NSMutableDictionary *errorInfo = [NSMutableDictionary dictionary];
|
|
26
35
|
errorInfo[NSLocalizedDescriptionKey] = [NSString stringWithFormat:@"Exception caught: %@", exception.name];
|
|
@@ -38,18 +47,45 @@ NSError *errorFromException(NSException *exception) {
|
|
|
38
47
|
RCT_EXPORT_MODULE()
|
|
39
48
|
|
|
40
49
|
-(void)startObserving {
|
|
41
|
-
NSLog(@"Alguien esta escuchando");
|
|
42
50
|
hasListeners = YES;
|
|
51
|
+
|
|
52
|
+
NSLog(@"Hay alguien escuchando");
|
|
53
|
+
|
|
54
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
55
|
+
selector:@selector(receiveTestNotification:)
|
|
56
|
+
name:@"kRookErrorBackground"
|
|
57
|
+
object:nil];
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
// Will be called when this module's last listener is removed, or on dealloc.
|
|
46
61
|
-(void)stopObserving {
|
|
47
62
|
hasListeners = NO;
|
|
48
|
-
|
|
63
|
+
|
|
64
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
- (NSArray<NSString *> *)supportedEvents {
|
|
52
|
-
return @[@"
|
|
68
|
+
return @[@"ROOK_NOTIFICATION"];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The above code is an Objective-C method that receives a notification and checks if the notification
|
|
72
|
+
// name is "kRookErrorBackground". If it is, it extracts information from the notification's userInfo
|
|
73
|
+
// dictionary, specifically an error object. It then creates a dictionary message containing the type,
|
|
74
|
+
// message, and code extracted from the error object. Finally, if there are listeners registered, it
|
|
75
|
+
// sends an event with the message dictionary to a specific event name "ROOK_NOTIFICATION".
|
|
76
|
+
- (void) receiveTestNotification:(NSNotification *) notification
|
|
77
|
+
{
|
|
78
|
+
if ([[notification name] isEqualToString:@"kRookErrorBackground"]) {
|
|
79
|
+
NSDictionary<NSString*, NSError *> *notificationInfo = [[notification userInfo] mutableCopy];
|
|
80
|
+
|
|
81
|
+
NSMutableDictionary *message = [[NSMutableDictionary alloc] init];
|
|
82
|
+
message[@"type"] = @"ROOK_APPLE_HEALTH_BACKGROUND_ERROR";
|
|
83
|
+
message[@"message"] = notificationInfo[@"Error"].localizedDescription;
|
|
84
|
+
message[@"code"] = notificationInfo[@"Error"].description;
|
|
85
|
+
|
|
86
|
+
if (hasListeners)
|
|
87
|
+
[self sendEventWithName:@"ROOK_NOTIFICATION" body: message];
|
|
88
|
+
}
|
|
53
89
|
}
|
|
54
90
|
|
|
55
91
|
RookConnectConfigurationManagerObjc *shared;
|
|
@@ -57,9 +93,21 @@ RookConnectPermissionsManager *permissionsManager;
|
|
|
57
93
|
RookSummaryManager *summaryManager;
|
|
58
94
|
RookEventsManager *eventsManager;
|
|
59
95
|
DataSourceManagerObjc *sourceManager;
|
|
60
|
-
|
|
96
|
+
UserManager *userManager;
|
|
61
97
|
|
|
62
98
|
// MARK: - Configuration
|
|
99
|
+
/**
|
|
100
|
+
* Initializes the Rook SDK with the provided configuration.
|
|
101
|
+
*
|
|
102
|
+
* @param data A dictionary containing the configuration parameters:
|
|
103
|
+
* - clientUUID: The unique identifier for the client.
|
|
104
|
+
* - password: The client's secret key.
|
|
105
|
+
* - enableEventsBackgroundSync: A boolean indicating whether to enable background sync for events.
|
|
106
|
+
* - environment: The environment in which the SDK is running (production, sandbox, or development).
|
|
107
|
+
* - enableLogs: A boolean indicating whether console logs should be enabled.
|
|
108
|
+
* @param resolve A block called upon successful initialization.
|
|
109
|
+
* @param reject A block called if an error occurs during initialization.
|
|
110
|
+
*/
|
|
63
111
|
RCT_EXPORT_METHOD(initRook:(NSDictionary *) data
|
|
64
112
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
65
113
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -97,17 +145,24 @@ RCT_EXPORT_METHOD(initRook:(NSDictionary *) data
|
|
|
97
145
|
summaryManager = [RookSummaryManager new];
|
|
98
146
|
eventsManager = [RookEventsManager new];
|
|
99
147
|
sourceManager = [DataSourceManagerObjc new];
|
|
148
|
+
userManager = [UserManager new];
|
|
100
149
|
|
|
101
150
|
resolve(@(YES));
|
|
102
151
|
}
|
|
103
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves the user ID from the user manager.
|
|
155
|
+
*
|
|
156
|
+
* @param resolve A block called with the user ID if the operation is successful.
|
|
157
|
+
* @param reject A block called if an error occurs while retrieving the user ID.
|
|
158
|
+
*/
|
|
104
159
|
RCT_EXPORT_METHOD(getUserID: (RCTPromiseResolveBlock)resolve
|
|
105
160
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
106
161
|
|
|
107
|
-
[
|
|
162
|
+
[userManager readUserIdWithCompletion:^(NSString * _Nullable userID, NSError * _Nullable error) {
|
|
108
163
|
|
|
109
164
|
if(error != nil) {
|
|
110
|
-
|
|
165
|
+
reject(error.description, error.localizedDescription, error);
|
|
111
166
|
return;
|
|
112
167
|
}
|
|
113
168
|
|
|
@@ -117,13 +172,19 @@ RCT_EXPORT_METHOD(getUserID: (RCTPromiseResolveBlock)resolve
|
|
|
117
172
|
|
|
118
173
|
}
|
|
119
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Update the user ID from the user manager.
|
|
177
|
+
*
|
|
178
|
+
* @param resolve A block called with the user ID if the operation is successful.
|
|
179
|
+
* @param reject A block called if an error occurs while retrieving the user ID.
|
|
180
|
+
*/
|
|
120
181
|
RCT_EXPORT_METHOD(updateUserID: (NSString *) userID
|
|
121
182
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
122
183
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
123
184
|
|
|
124
|
-
[
|
|
185
|
+
[userManager updateUserId:userID completion:^(BOOL success, NSError * _Nullable error) {
|
|
125
186
|
if(error != nil) {
|
|
126
|
-
|
|
187
|
+
reject(error.description, error.localizedDescription, error);
|
|
127
188
|
return;
|
|
128
189
|
}
|
|
129
190
|
|
|
@@ -132,12 +193,18 @@ RCT_EXPORT_METHOD(updateUserID: (NSString *) userID
|
|
|
132
193
|
|
|
133
194
|
}
|
|
134
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Clear the user ID from the user manager.
|
|
198
|
+
*
|
|
199
|
+
* @param resolve A block called with the user ID if the operation is successful.
|
|
200
|
+
* @param reject A block called if an error occurs while retrieving the user ID.
|
|
201
|
+
*/
|
|
135
202
|
RCT_EXPORT_METHOD(clearUserID: (RCTPromiseResolveBlock)resolve
|
|
136
203
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
137
204
|
|
|
138
|
-
[
|
|
205
|
+
[userManager clearUserWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
139
206
|
if(error != nil) {
|
|
140
|
-
|
|
207
|
+
reject(error.description, error.localizedDescription, error);
|
|
141
208
|
return;
|
|
142
209
|
}
|
|
143
210
|
|
|
@@ -146,12 +213,18 @@ RCT_EXPORT_METHOD(clearUserID: (RCTPromiseResolveBlock)resolve
|
|
|
146
213
|
|
|
147
214
|
}
|
|
148
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Remove the user ID from the ROOK services.
|
|
218
|
+
*
|
|
219
|
+
* @param resolve A block called with the user ID if the operation is successful.
|
|
220
|
+
* @param reject A block called if an error occurs while retrieving the user ID.
|
|
221
|
+
*/
|
|
149
222
|
RCT_EXPORT_METHOD(removeUserFromRook: (RCTPromiseResolveBlock)resolve
|
|
150
223
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
151
224
|
|
|
152
|
-
[
|
|
225
|
+
[userManager removeUserFromRookWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
153
226
|
if(error != nil) {
|
|
154
|
-
|
|
227
|
+
reject(error.description, error.localizedDescription, error);
|
|
155
228
|
return;
|
|
156
229
|
}
|
|
157
230
|
|
|
@@ -160,6 +233,12 @@ RCT_EXPORT_METHOD(removeUserFromRook: (RCTPromiseResolveBlock)resolve
|
|
|
160
233
|
|
|
161
234
|
}
|
|
162
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Checks if background sync is enabled.
|
|
238
|
+
*
|
|
239
|
+
* @param resolve A block called with a boolean value indicating whether sync is enabled.
|
|
240
|
+
* @param reject A block called if an error occurs (not applicable here).
|
|
241
|
+
*/
|
|
163
242
|
RCT_EXPORT_METHOD(isSyncEnable: (RCTPromiseResolveBlock)resolve
|
|
164
243
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
165
244
|
|
|
@@ -167,6 +246,12 @@ RCT_EXPORT_METHOD(isSyncEnable: (RCTPromiseResolveBlock)resolve
|
|
|
167
246
|
resolve(@(result));
|
|
168
247
|
}
|
|
169
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Enables background sync.
|
|
251
|
+
*
|
|
252
|
+
* @param resolve A block called upon successfully enabling sync.
|
|
253
|
+
* @param reject A block called if an error occurs (not applicable here).
|
|
254
|
+
*/
|
|
170
255
|
RCT_EXPORT_METHOD(enableSync: (RCTPromiseResolveBlock)resolve
|
|
171
256
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
172
257
|
|
|
@@ -175,6 +260,12 @@ RCT_EXPORT_METHOD(enableSync: (RCTPromiseResolveBlock)resolve
|
|
|
175
260
|
|
|
176
261
|
}
|
|
177
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Disable background sync.
|
|
265
|
+
*
|
|
266
|
+
* @param resolve A block called upon successfully enabling sync.
|
|
267
|
+
* @param reject A block called if an error occurs (not applicable here).
|
|
268
|
+
*/
|
|
178
269
|
RCT_EXPORT_METHOD(disableSync: (RCTPromiseResolveBlock)resolve
|
|
179
270
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
180
271
|
|
|
@@ -182,12 +273,18 @@ RCT_EXPORT_METHOD(disableSync: (RCTPromiseResolveBlock)resolve
|
|
|
182
273
|
resolve(@(YES));
|
|
183
274
|
}
|
|
184
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Synchronizes the user's time zone with the user manager.
|
|
278
|
+
*
|
|
279
|
+
* @param resolve A block called with a boolean value indicating whether the time zone sync was successful.
|
|
280
|
+
* @param reject A block called if an error occurs during the sync process.
|
|
281
|
+
*/
|
|
185
282
|
RCT_EXPORT_METHOD(syncUserTimeZone: (RCTPromiseResolveBlock)resolve
|
|
186
283
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
187
284
|
|
|
188
|
-
[
|
|
285
|
+
[userManager syncUserTimeZoneWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
189
286
|
if(error != nil) {
|
|
190
|
-
|
|
287
|
+
reject(error.description, error.localizedDescription, error);
|
|
191
288
|
return;
|
|
192
289
|
}
|
|
193
290
|
|
|
@@ -197,12 +294,18 @@ RCT_EXPORT_METHOD(syncUserTimeZone: (RCTPromiseResolveBlock)resolve
|
|
|
197
294
|
}
|
|
198
295
|
|
|
199
296
|
// MARK: - Permissions
|
|
297
|
+
/**
|
|
298
|
+
* Requests all available permissions from the permissions manager.
|
|
299
|
+
*
|
|
300
|
+
* @param resolve A block called with a boolean value indicating whether all permissions were successfully requested.
|
|
301
|
+
* @param reject A block called if an error occurs during the permission request process.
|
|
302
|
+
*/
|
|
200
303
|
RCT_EXPORT_METHOD(requestAllPermissions: (RCTPromiseResolveBlock)resolve
|
|
201
304
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
202
305
|
|
|
203
306
|
[permissionsManager requestAllPermissionsObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
204
307
|
if(error != nil) {
|
|
205
|
-
|
|
308
|
+
reject(error.description, error.localizedDescription, error);
|
|
206
309
|
return;
|
|
207
310
|
}
|
|
208
311
|
|
|
@@ -211,12 +314,18 @@ RCT_EXPORT_METHOD(requestAllPermissions: (RCTPromiseResolveBlock)resolve
|
|
|
211
314
|
|
|
212
315
|
}
|
|
213
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Requests sleep permissions from the permissions manager.
|
|
319
|
+
*
|
|
320
|
+
* @param resolve A block called with a boolean value indicating whether all permissions were successfully requested.
|
|
321
|
+
* @param reject A block called if an error occurs during the permission request process.
|
|
322
|
+
*/
|
|
214
323
|
RCT_EXPORT_METHOD(requestSleepPermissions: (RCTPromiseResolveBlock)resolve
|
|
215
324
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
216
325
|
|
|
217
326
|
[permissionsManager requestSleepPermissionsObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
218
327
|
if(error != nil) {
|
|
219
|
-
|
|
328
|
+
reject(error.description, error.localizedDescription, error);
|
|
220
329
|
return;
|
|
221
330
|
}
|
|
222
331
|
|
|
@@ -225,11 +334,17 @@ RCT_EXPORT_METHOD(requestSleepPermissions: (RCTPromiseResolveBlock)resolve
|
|
|
225
334
|
|
|
226
335
|
}
|
|
227
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Requests user info permissions from the permissions manager.
|
|
339
|
+
*
|
|
340
|
+
* @param resolve A block called with a boolean value indicating whether all permissions were successfully requested.
|
|
341
|
+
* @param reject A block called if an error occurs during the permission request process.
|
|
342
|
+
*/
|
|
228
343
|
RCT_EXPORT_METHOD(requestUserInfoPermissions: (RCTPromiseResolveBlock)resolve
|
|
229
344
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
230
345
|
[permissionsManager requestUserInfoPermissionsObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
231
346
|
if(error != nil) {
|
|
232
|
-
|
|
347
|
+
reject(error.description, error.localizedDescription, error);
|
|
233
348
|
return;
|
|
234
349
|
}
|
|
235
350
|
|
|
@@ -238,12 +353,18 @@ RCT_EXPORT_METHOD(requestUserInfoPermissions: (RCTPromiseResolveBlock)resolve
|
|
|
238
353
|
|
|
239
354
|
}
|
|
240
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Requests physical permissions from the permissions manager.
|
|
358
|
+
*
|
|
359
|
+
* @param resolve A block called with a boolean value indicating whether all permissions were successfully requested.
|
|
360
|
+
* @param reject A block called if an error occurs during the permission request process.
|
|
361
|
+
*/
|
|
241
362
|
RCT_EXPORT_METHOD(requestPhysicalPermissions: (RCTPromiseResolveBlock)resolve
|
|
242
363
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
243
364
|
|
|
244
365
|
[permissionsManager requestPhysicalPermissionsObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
245
366
|
if(error != nil) {
|
|
246
|
-
|
|
367
|
+
reject(error.description, error.localizedDescription, error);
|
|
247
368
|
return;
|
|
248
369
|
}
|
|
249
370
|
|
|
@@ -252,12 +373,18 @@ RCT_EXPORT_METHOD(requestPhysicalPermissions: (RCTPromiseResolveBlock)resolve
|
|
|
252
373
|
|
|
253
374
|
}
|
|
254
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Requests body permissions from the permissions manager.
|
|
378
|
+
*
|
|
379
|
+
* @param resolve A block called with a boolean value indicating whether all permissions were successfully requested.
|
|
380
|
+
* @param reject A block called if an error occurs during the permission request process.
|
|
381
|
+
*/
|
|
255
382
|
RCT_EXPORT_METHOD(requestBodyPermissions: (RCTPromiseResolveBlock)resolve
|
|
256
383
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
257
384
|
|
|
258
385
|
[permissionsManager requestBodyPermissionsObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
259
386
|
if(error != nil) {
|
|
260
|
-
|
|
387
|
+
reject(error.description, error.localizedDescription, error);
|
|
261
388
|
return;
|
|
262
389
|
}
|
|
263
390
|
|
|
@@ -266,7 +393,58 @@ RCT_EXPORT_METHOD(requestBodyPermissions: (RCTPromiseResolveBlock)resolve
|
|
|
266
393
|
|
|
267
394
|
}
|
|
268
395
|
|
|
396
|
+
/**
|
|
397
|
+
* Opens the Apple Health settings on the user's device.
|
|
398
|
+
*
|
|
399
|
+
* @param resolve A block called with a boolean value indicating whether the Apple Health settings were successfully opened.
|
|
400
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
401
|
+
*/
|
|
402
|
+
RCT_EXPORT_METHOD(openAppleHealthSettings: (RCTPromiseResolveBlock)resolve
|
|
403
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
404
|
+
|
|
405
|
+
NSURL *urlSettings = [NSURL URLWithString:@"x-apple-health://"];
|
|
406
|
+
|
|
407
|
+
if (!urlSettings) {
|
|
408
|
+
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"Apple Health is not installed on iOS."};
|
|
409
|
+
NSError *error = [NSError errorWithDomain:@"io.ROOK.SDK" code:1001 userInfo:userInfo];
|
|
410
|
+
reject(error.description, error.localizedDescription, error);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
416
|
+
[[UIApplication sharedApplication] openURL:urlSettings options:@{} completionHandler:^(BOOL success) {
|
|
417
|
+
resolve(@(success));
|
|
418
|
+
}];
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Checks the permission status for a specific data type in Apple Health.
|
|
424
|
+
*
|
|
425
|
+
* @param type The type of data for which the permission status is being checked (e.g., steps, sleep).
|
|
426
|
+
* @param resolve A block called with the permission status (e.g., authorized, denied, not determined).
|
|
427
|
+
* @param reject A block called if an error occurs (not used here).
|
|
428
|
+
*/
|
|
429
|
+
RCT_EXPORT_METHOD(checkPermissionsStatus: (NSString * _Nullable) type
|
|
430
|
+
resolve: (RCTPromiseResolveBlock) resolve
|
|
431
|
+
reject: (RCTPromiseRejectBlock) reject) {
|
|
432
|
+
|
|
433
|
+
[permissionsManager checkPermissionStatusWithType:type completionHandler:^(NSString * _Nonnull status) {
|
|
434
|
+
|
|
435
|
+
resolve(status);
|
|
436
|
+
|
|
437
|
+
}];
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
269
441
|
// MARK: - Summaries
|
|
442
|
+
/**
|
|
443
|
+
* Syncs the yesterday summaries
|
|
444
|
+
*
|
|
445
|
+
* @param resolve A block called with a boolean value indicating whether the summaries were successfully sync.
|
|
446
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
447
|
+
*/
|
|
270
448
|
RCT_EXPORT_METHOD(syncYesterdaySummaries: (RCTPromiseResolveBlock)resolve
|
|
271
449
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
272
450
|
|
|
@@ -276,13 +454,19 @@ RCT_EXPORT_METHOD(syncYesterdaySummaries: (RCTPromiseResolveBlock)resolve
|
|
|
276
454
|
|
|
277
455
|
}
|
|
278
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Sync sleep summary
|
|
459
|
+
*
|
|
460
|
+
* @param resolve A block called with a boolean value indicating whether the sleep summary were successfully sync.
|
|
461
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
462
|
+
*/
|
|
279
463
|
RCT_EXPORT_METHOD(syncSleepSummary: (NSString *) dateString
|
|
280
464
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
281
465
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
282
466
|
|
|
283
467
|
[summaryManager syncSleepSummaryObjcWithForm:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
284
468
|
if(error != nil) {
|
|
285
|
-
|
|
469
|
+
reject(error.description, error.localizedDescription, error);
|
|
286
470
|
return;
|
|
287
471
|
}
|
|
288
472
|
|
|
@@ -291,13 +475,19 @@ RCT_EXPORT_METHOD(syncSleepSummary: (NSString *) dateString
|
|
|
291
475
|
|
|
292
476
|
}
|
|
293
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Sync physical summary
|
|
480
|
+
*
|
|
481
|
+
* @param resolve A block called with a boolean value indicating whether the physical summary were successfully sync.
|
|
482
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
483
|
+
*/
|
|
294
484
|
RCT_EXPORT_METHOD(syncPhysicalSummary: (NSString *) dateString
|
|
295
485
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
296
486
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
297
487
|
|
|
298
488
|
[summaryManager syncPhysicalSummaryObjcWithForm:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
299
489
|
if(error != nil) {
|
|
300
|
-
|
|
490
|
+
reject(error.description, error.localizedDescription, error);
|
|
301
491
|
return;
|
|
302
492
|
}
|
|
303
493
|
|
|
@@ -306,13 +496,19 @@ RCT_EXPORT_METHOD(syncPhysicalSummary: (NSString *) dateString
|
|
|
306
496
|
|
|
307
497
|
}
|
|
308
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Sync body summary
|
|
501
|
+
*
|
|
502
|
+
* @param resolve A block called with a boolean value indicating whether the body summary were successfully sync.
|
|
503
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
504
|
+
*/
|
|
309
505
|
RCT_EXPORT_METHOD(syncBodySummary: (NSString *) dateString
|
|
310
506
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
311
507
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
312
508
|
|
|
313
509
|
[summaryManager syncBodySummaryObjcFrom:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
314
510
|
if(error != nil) {
|
|
315
|
-
|
|
511
|
+
reject(error.description, error.localizedDescription, error);
|
|
316
512
|
return;
|
|
317
513
|
}
|
|
318
514
|
|
|
@@ -321,12 +517,18 @@ RCT_EXPORT_METHOD(syncBodySummary: (NSString *) dateString
|
|
|
321
517
|
|
|
322
518
|
}
|
|
323
519
|
|
|
520
|
+
/**
|
|
521
|
+
* Sync summaries that couldnt be sync due to an error
|
|
522
|
+
*
|
|
523
|
+
* @param resolve A block called with a boolean value indicating whether the summaries were successfully sync.
|
|
524
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
525
|
+
*/
|
|
324
526
|
RCT_EXPORT_METHOD(syncPendingSummaries: (RCTPromiseResolveBlock) resolve
|
|
325
527
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
326
528
|
|
|
327
529
|
[summaryManager syncPendingSummariesObjcWithCompletion:^(BOOL success, NSError * _Nullable error) {
|
|
328
530
|
if(error != nil) {
|
|
329
|
-
|
|
531
|
+
reject(error.description, error.localizedDescription, error);
|
|
330
532
|
return;
|
|
331
533
|
}
|
|
332
534
|
|
|
@@ -336,6 +538,12 @@ RCT_EXPORT_METHOD(syncPendingSummaries: (RCTPromiseResolveBlock) resolve
|
|
|
336
538
|
}
|
|
337
539
|
|
|
338
540
|
// MARK: - Events
|
|
541
|
+
/**
|
|
542
|
+
* Syncs the events
|
|
543
|
+
*
|
|
544
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
545
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
546
|
+
*/
|
|
339
547
|
RCT_EXPORT_METHOD(syncYesterdayEvents: (RCTPromiseResolveBlock)resolve
|
|
340
548
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
341
549
|
|
|
@@ -345,13 +553,19 @@ RCT_EXPORT_METHOD(syncYesterdayEvents: (RCTPromiseResolveBlock)resolve
|
|
|
345
553
|
|
|
346
554
|
}
|
|
347
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Sync body heart rate event
|
|
558
|
+
*
|
|
559
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
560
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
561
|
+
*/
|
|
348
562
|
RCT_EXPORT_METHOD(syncBodyHeartRateEvent: (NSString *) dateString
|
|
349
563
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
350
564
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
351
565
|
|
|
352
566
|
[eventsManager syncBodyHeartRateEventObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
353
567
|
if(error != nil) {
|
|
354
|
-
|
|
568
|
+
reject(error.description, error.localizedDescription, error);
|
|
355
569
|
return;
|
|
356
570
|
}
|
|
357
571
|
|
|
@@ -359,6 +573,12 @@ RCT_EXPORT_METHOD(syncBodyHeartRateEvent: (NSString *) dateString
|
|
|
359
573
|
}];
|
|
360
574
|
}
|
|
361
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Sync physical heart rate event
|
|
578
|
+
*
|
|
579
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
580
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
581
|
+
*/
|
|
362
582
|
RCT_EXPORT_METHOD(syncPhysicalHeartRateEvent: (NSString *) dateString
|
|
363
583
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
364
584
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -366,7 +586,7 @@ RCT_EXPORT_METHOD(syncPhysicalHeartRateEvent: (NSString *) dateString
|
|
|
366
586
|
[eventsManager
|
|
367
587
|
syncPhysicalHeartRateEventObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
368
588
|
if(error != nil) {
|
|
369
|
-
|
|
589
|
+
reject(error.description, error.localizedDescription, error);
|
|
370
590
|
return;
|
|
371
591
|
}
|
|
372
592
|
|
|
@@ -374,13 +594,19 @@ RCT_EXPORT_METHOD(syncPhysicalHeartRateEvent: (NSString *) dateString
|
|
|
374
594
|
}];
|
|
375
595
|
}
|
|
376
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Sync body oxygenation event
|
|
599
|
+
*
|
|
600
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
601
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
602
|
+
*/
|
|
377
603
|
RCT_EXPORT_METHOD(syncBodyOxygenationEvent: (NSString *) dateString
|
|
378
604
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
379
605
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
380
606
|
|
|
381
607
|
[eventsManager syncBodyOxygenationEventObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
382
608
|
if(error != nil) {
|
|
383
|
-
|
|
609
|
+
reject(error.description, error.localizedDescription, error);
|
|
384
610
|
return;
|
|
385
611
|
}
|
|
386
612
|
|
|
@@ -388,13 +614,19 @@ RCT_EXPORT_METHOD(syncBodyOxygenationEvent: (NSString *) dateString
|
|
|
388
614
|
}];
|
|
389
615
|
}
|
|
390
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Sync physical oxygenation event
|
|
619
|
+
*
|
|
620
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
621
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
622
|
+
*/
|
|
391
623
|
RCT_EXPORT_METHOD(syncPhysicalOxygenationEvent: (NSString *) dateString
|
|
392
624
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
393
625
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
394
626
|
|
|
395
627
|
[eventsManager syncPhysicalOxygenationEventObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
396
628
|
if(error != nil) {
|
|
397
|
-
|
|
629
|
+
reject(error.description, error.localizedDescription, error);
|
|
398
630
|
return;
|
|
399
631
|
}
|
|
400
632
|
|
|
@@ -402,13 +634,19 @@ RCT_EXPORT_METHOD(syncPhysicalOxygenationEvent: (NSString *) dateString
|
|
|
402
634
|
}];
|
|
403
635
|
}
|
|
404
636
|
|
|
637
|
+
/**
|
|
638
|
+
* Sync training event
|
|
639
|
+
*
|
|
640
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
641
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
642
|
+
*/
|
|
405
643
|
RCT_EXPORT_METHOD(syncTrainingEvent: (NSString *) dateString
|
|
406
644
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
407
645
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
408
646
|
|
|
409
647
|
[eventsManager syncTrainingEventObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
410
648
|
if(error != nil) {
|
|
411
|
-
|
|
649
|
+
reject(error.description, error.localizedDescription, error);
|
|
412
650
|
return;
|
|
413
651
|
}
|
|
414
652
|
|
|
@@ -416,13 +654,19 @@ RCT_EXPORT_METHOD(syncTrainingEvent: (NSString *) dateString
|
|
|
416
654
|
}];
|
|
417
655
|
}
|
|
418
656
|
|
|
657
|
+
/**
|
|
658
|
+
* Sync temperature event
|
|
659
|
+
*
|
|
660
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
661
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
662
|
+
*/
|
|
419
663
|
RCT_EXPORT_METHOD(syncTemperatureEvent: (NSString *) dateString
|
|
420
664
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
421
665
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
422
666
|
|
|
423
667
|
[eventsManager syncTemperatureEventsObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
424
668
|
if(error != nil) {
|
|
425
|
-
|
|
669
|
+
reject(error.description, error.localizedDescription, error);
|
|
426
670
|
return;
|
|
427
671
|
}
|
|
428
672
|
|
|
@@ -430,13 +674,19 @@ RCT_EXPORT_METHOD(syncTemperatureEvent: (NSString *) dateString
|
|
|
430
674
|
}];
|
|
431
675
|
}
|
|
432
676
|
|
|
677
|
+
/**
|
|
678
|
+
* Sync blood pressure event
|
|
679
|
+
*
|
|
680
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
681
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
682
|
+
*/
|
|
433
683
|
RCT_EXPORT_METHOD(syncPressureEvent: (NSString *) dateString
|
|
434
684
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
435
685
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
436
686
|
|
|
437
687
|
[eventsManager syncPressureEventsObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
438
688
|
if(error != nil) {
|
|
439
|
-
|
|
689
|
+
reject(error.description, error.localizedDescription, error);
|
|
440
690
|
return;
|
|
441
691
|
}
|
|
442
692
|
|
|
@@ -444,13 +694,19 @@ RCT_EXPORT_METHOD(syncPressureEvent: (NSString *) dateString
|
|
|
444
694
|
}];
|
|
445
695
|
}
|
|
446
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Sync blood glucose event
|
|
699
|
+
*
|
|
700
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
701
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
702
|
+
*/
|
|
447
703
|
RCT_EXPORT_METHOD(syncGlucoseEvent: (NSString *) dateString
|
|
448
704
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
449
705
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
450
706
|
|
|
451
707
|
[eventsManager syncGlucoseEventsObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
452
708
|
if(error != nil) {
|
|
453
|
-
|
|
709
|
+
reject(error.description, error.localizedDescription, error);
|
|
454
710
|
return;
|
|
455
711
|
}
|
|
456
712
|
|
|
@@ -458,13 +714,19 @@ RCT_EXPORT_METHOD(syncGlucoseEvent: (NSString *) dateString
|
|
|
458
714
|
}];
|
|
459
715
|
}
|
|
460
716
|
|
|
717
|
+
/**
|
|
718
|
+
* Sync body metrics event
|
|
719
|
+
*
|
|
720
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
721
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
722
|
+
*/
|
|
461
723
|
RCT_EXPORT_METHOD(syncBodyMetricsEvent: (NSString *) dateString
|
|
462
724
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
463
725
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
464
726
|
|
|
465
727
|
[eventsManager syncBodyMetricsEventsObjcWithDate:parseDateFromString(dateString) completion:^(BOOL success, NSError * _Nullable error) {
|
|
466
728
|
if(error != nil) {
|
|
467
|
-
|
|
729
|
+
reject(error.description, error.localizedDescription, error);
|
|
468
730
|
return;
|
|
469
731
|
}
|
|
470
732
|
|
|
@@ -473,7 +735,13 @@ RCT_EXPORT_METHOD(syncBodyMetricsEvent: (NSString *) dateString
|
|
|
473
735
|
}
|
|
474
736
|
|
|
475
737
|
// MARK: - Background
|
|
476
|
-
|
|
738
|
+
/**
|
|
739
|
+
* Enable the background sync, this will automatically upload events and summaries
|
|
740
|
+
* at the moment the user enables this feature.
|
|
741
|
+
*
|
|
742
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
743
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
744
|
+
*/
|
|
477
745
|
RCT_EXPORT_METHOD(enableBackGroundUpdates: (RCTPromiseResolveBlock) resolve
|
|
478
746
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
479
747
|
|
|
@@ -482,30 +750,52 @@ RCT_EXPORT_METHOD(enableBackGroundUpdates: (RCTPromiseResolveBlock) resolve
|
|
|
482
750
|
resolve(@(YES));
|
|
483
751
|
}
|
|
484
752
|
|
|
753
|
+
/**
|
|
754
|
+
* Disable the background sync
|
|
755
|
+
*
|
|
756
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
757
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
758
|
+
*/
|
|
485
759
|
RCT_EXPORT_METHOD(disableBackGroundUpdates: (RCTPromiseResolveBlock) resolve
|
|
486
760
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
487
761
|
|
|
488
762
|
[[RookBackGroundSync shared] disableBackGroundForSummaries];
|
|
489
763
|
|
|
490
|
-
[[RookBackGroundSync shared]
|
|
491
|
-
|
|
492
|
-
|
|
764
|
+
[[RookBackGroundSync shared] disableBackGroundForEvents];
|
|
765
|
+
|
|
766
|
+
resolve(@(YES));
|
|
493
767
|
}
|
|
494
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Enable background sync for summaries only
|
|
771
|
+
*
|
|
772
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
773
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
774
|
+
*/
|
|
495
775
|
RCT_EXPORT_METHOD(enableBackGroundEventUpdates: (RCTPromiseResolveBlock) resolve
|
|
496
776
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
497
777
|
[[RookBackGroundSync shared] enableBackGroundForEvents];
|
|
498
778
|
resolve(@(YES));
|
|
499
779
|
}
|
|
500
780
|
|
|
781
|
+
/**
|
|
782
|
+
* Disable the backGround sync just for events
|
|
783
|
+
*
|
|
784
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
785
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
786
|
+
*/
|
|
501
787
|
RCT_EXPORT_METHOD(disableBackGroundEventUpdates: (RCTPromiseResolveBlock) resolve
|
|
502
788
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
503
789
|
|
|
504
|
-
[[RookBackGroundSync shared]
|
|
505
|
-
resolve(@(YES));
|
|
506
|
-
}];
|
|
790
|
+
[[RookBackGroundSync shared] disableBackGroundForEvents];
|
|
507
791
|
}
|
|
508
792
|
|
|
793
|
+
/**
|
|
794
|
+
* Check if the background sync for summaries are enabled
|
|
795
|
+
*
|
|
796
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
797
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
798
|
+
*/
|
|
509
799
|
RCT_EXPORT_METHOD(isBackGroundForSummariesEnable: (RCTPromiseResolveBlock) resolve
|
|
510
800
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
511
801
|
|
|
@@ -513,6 +803,12 @@ RCT_EXPORT_METHOD(isBackGroundForSummariesEnable: (RCTPromiseResolveBlock) resol
|
|
|
513
803
|
resolve(@(result));
|
|
514
804
|
}
|
|
515
805
|
|
|
806
|
+
/**
|
|
807
|
+
* Check if the background sync for events are enabled
|
|
808
|
+
*
|
|
809
|
+
* @param resolve A block called with a boolean value indicating whether the events were successfully sync.
|
|
810
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
811
|
+
*/
|
|
516
812
|
RCT_EXPORT_METHOD(isBackGroundForEventsEnable: (RCTPromiseResolveBlock) resolve
|
|
517
813
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
518
814
|
|
|
@@ -521,12 +817,18 @@ RCT_EXPORT_METHOD(isBackGroundForEventsEnable: (RCTPromiseResolveBlock) resolve
|
|
|
521
817
|
}
|
|
522
818
|
|
|
523
819
|
// MARK: - Variables
|
|
820
|
+
/**
|
|
821
|
+
* Extract the steps from apple health
|
|
822
|
+
*
|
|
823
|
+
* @param resolve A block called with a string value indicating the steps.
|
|
824
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
825
|
+
*/
|
|
524
826
|
RCT_EXPORT_METHOD(getTodaySteps: (RCTPromiseResolveBlock) resolve
|
|
525
827
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
526
828
|
|
|
527
829
|
[eventsManager getTodayStepCountWithCompletion:^(NSInteger steps, NSError * _Nullable error) {
|
|
528
830
|
if(error != nil) {
|
|
529
|
-
|
|
831
|
+
reject(error.description, error.localizedDescription, error);
|
|
530
832
|
return;
|
|
531
833
|
}
|
|
532
834
|
resolve(@(steps));
|
|
@@ -535,6 +837,12 @@ RCT_EXPORT_METHOD(getTodaySteps: (RCTPromiseResolveBlock) resolve
|
|
|
535
837
|
}
|
|
536
838
|
|
|
537
839
|
// MARK: - Connection Page
|
|
840
|
+
/**
|
|
841
|
+
* Check the authorizers and retrieve the sources available and configured
|
|
842
|
+
*
|
|
843
|
+
* @param resolve A block called with a boolean value indicating whether the result.
|
|
844
|
+
* @param reject A block called if an error occurs.
|
|
845
|
+
*/
|
|
538
846
|
RCT_EXPORT_METHOD(getAvailableDataSources: (NSDictionary *) options
|
|
539
847
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
540
848
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -544,7 +852,7 @@ RCT_EXPORT_METHOD(getAvailableDataSources: (NSDictionary *) options
|
|
|
544
852
|
[sourceManager getAvailableDataSourcesWithRedirectURL:redirectURL
|
|
545
853
|
completion:^(NSArray<NSDictionary<NSString *,id> *> * _Nullable sources, NSError * _Nullable error) {
|
|
546
854
|
if (error) {
|
|
547
|
-
|
|
855
|
+
reject(error.description, error.localizedDescription, error);
|
|
548
856
|
return;
|
|
549
857
|
}
|
|
550
858
|
|
|
@@ -557,6 +865,12 @@ RCT_EXPORT_METHOD(getAvailableDataSources: (NSDictionary *) options
|
|
|
557
865
|
}];
|
|
558
866
|
}
|
|
559
867
|
|
|
868
|
+
/**
|
|
869
|
+
* Check the authorizers and present a default view.
|
|
870
|
+
*
|
|
871
|
+
* @param resolve A block called with a boolean value indicating whether the result.
|
|
872
|
+
* @param reject A block called if an error occurs.
|
|
873
|
+
*/
|
|
560
874
|
RCT_EXPORT_METHOD(presentDataSourceView: (NSDictionary *) options
|
|
561
875
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
562
876
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -565,7 +879,7 @@ RCT_EXPORT_METHOD(presentDataSourceView: (NSDictionary *) options
|
|
|
565
879
|
|
|
566
880
|
[sourceManager presentDataSourceViewWithRedirectURL:redirectURL completion:^(BOOL succeed, NSError * _Nullable error) {
|
|
567
881
|
if (error) {
|
|
568
|
-
reject(
|
|
882
|
+
reject(error.description, error.localizedDescription, error);
|
|
569
883
|
return;
|
|
570
884
|
}
|
|
571
885
|
|
|
@@ -573,6 +887,43 @@ RCT_EXPORT_METHOD(presentDataSourceView: (NSDictionary *) options
|
|
|
573
887
|
}];
|
|
574
888
|
});
|
|
575
889
|
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Revoke the access to a API source
|
|
893
|
+
*
|
|
894
|
+
* @param resolve A block called with a boolean value indicating whether the result is.
|
|
895
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
896
|
+
*/
|
|
897
|
+
RCT_EXPORT_METHOD(revokeDataSource: (NSString *) source
|
|
898
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
899
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
900
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
901
|
+
[userManager revokeDataSourceWithDataSource:source completion:^(BOOL succeed, NSError * _Nullable error) {
|
|
902
|
+
if (error) {
|
|
903
|
+
reject(error.description, error.localizedDescription, error);
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
resolve(@(succeed));
|
|
908
|
+
}];
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// MARK: - RN Broadcast
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Internal method to send messages to broadcast channel
|
|
916
|
+
*
|
|
917
|
+
* @param resolve A block called with a boolean value indicating whether the result is.
|
|
918
|
+
* @param reject A block called if an error occurs, such as Apple Health not being installed.
|
|
919
|
+
*/
|
|
920
|
+
RCT_EXPORT_METHOD(sendMessageToBroadcast: (NSDictionary *) message
|
|
921
|
+
resolve: (RCTPromiseResolveBlock) resolve
|
|
922
|
+
reject: (RCTPromiseRejectBlock) reject) {
|
|
923
|
+
if(hasListeners) {
|
|
924
|
+
[self sendEventWithName:@"ROOK_NOTIFICATION" body:message];
|
|
925
|
+
}
|
|
926
|
+
}
|
|
576
927
|
@end
|
|
577
928
|
|
|
578
929
|
|