@flomentumsolutions/capacitor-health-extended 0.0.12 → 0.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.
|
@@ -237,23 +237,53 @@ public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
237
237
|
|
|
238
238
|
// Convenience methods for specific data types
|
|
239
239
|
@objc func queryWeight(_ call: CAPPluginCall) {
|
|
240
|
-
call
|
|
241
|
-
queryLatestSample(call)
|
|
240
|
+
queryLatestSampleWithType(call, dataType: "weight")
|
|
242
241
|
}
|
|
243
242
|
|
|
244
243
|
@objc func queryHeight(_ call: CAPPluginCall) {
|
|
245
|
-
call
|
|
246
|
-
queryLatestSample(call)
|
|
244
|
+
queryLatestSampleWithType(call, dataType: "height")
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
@objc func queryHeartRate(_ call: CAPPluginCall) {
|
|
250
|
-
call
|
|
251
|
-
queryLatestSample(call)
|
|
248
|
+
queryLatestSampleWithType(call, dataType: "heart-rate")
|
|
252
249
|
}
|
|
253
250
|
|
|
254
251
|
@objc func querySteps(_ call: CAPPluginCall) {
|
|
255
|
-
call
|
|
256
|
-
|
|
252
|
+
queryLatestSampleWithType(call, dataType: "steps")
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private func queryLatestSampleWithType(_ call: CAPPluginCall, dataType: String) {
|
|
256
|
+
// Safely coerce the original options into a [String: Any] JSObject.
|
|
257
|
+
let originalOptions = call.options as? [String: Any] ?? [:]
|
|
258
|
+
var params = originalOptions
|
|
259
|
+
params["dataType"] = dataType
|
|
260
|
+
|
|
261
|
+
// Create a proxy CAPPluginCall using the CURRENT (Capacitor 6) designated initializer.
|
|
262
|
+
// NOTE: The older init(callbackId:options:success:error:) is deprecated and *failable*,
|
|
263
|
+
// so we use the newer initializer that requires a method name. Guard against failure.
|
|
264
|
+
guard let proxyCall = CAPPluginCall(
|
|
265
|
+
callbackId: call.callbackId,
|
|
266
|
+
methodName: "queryLatestSample", // required in new API
|
|
267
|
+
options: params,
|
|
268
|
+
success: { result, _ in
|
|
269
|
+
// Forward the resolved data back to the original JS caller.
|
|
270
|
+
call.resolve(result?.data ?? [:])
|
|
271
|
+
},
|
|
272
|
+
error: { capError in
|
|
273
|
+
// Forward the error to the original call in the legacy reject format.
|
|
274
|
+
if let capError = capError {
|
|
275
|
+
call.reject(capError.message, capError.code, capError.error, capError.data)
|
|
276
|
+
} else {
|
|
277
|
+
call.reject("Unknown native error")
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
) else {
|
|
281
|
+
call.reject("Failed to create proxy call")
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Delegate the actual HealthKit fetch to the common implementation.
|
|
286
|
+
queryLatestSample(proxyCall)
|
|
257
287
|
}
|
|
258
288
|
|
|
259
289
|
@objc func openAppleHealthSettings(_ call: CAPPluginCall) {
|
package/package.json
CHANGED