ios-pwa-wrap icon indicating copy to clipboard operation
ios-pwa-wrap copied to clipboard

Adding HealthKit support

Open haszz opened this issue 4 months ago • 0 comments

Title: Add HealthKit Integration for Fitness and Activity Data Retrieval


Description: This pull request introduces HealthKit support to the iOS PWA wrapper, providing capabilities for data authorization, retrieval, and JavaScript communication for fitness and activity data. The following major functionalities have been added:

Key Features and Changes:

  1. HealthKit Setup and Authorization:

    • setupHealthKit: Ensures HealthKit is available on the device.
    • requestAuthorization: Requests read access to specific HealthKit data types, including steps, distance, active energy, heart rate, and more.
    • checkAuthorizationStatus: Checks the authorization status for a specified HealthKit data type.
  2. Data Retrieval and Aggregation:

    • fetchHealthData: Aggregates data for steps, distance, and energy burned over the past three days and provides workout summaries.
    • fetchDetailedWorkouts: Retrieves details of recent workouts, including specific metrics such as active energy, elevation, speed, heart rate data, and step count.
  3. JavaScript Communication:

    • handleHealthKitPermission: Notifies the web view of authorization results (granted or denied).
    • handleHealthKitData: Passes retrieved HealthKit data to the web view in JSON format to enable further processing or display in the PWA.
  4. Helper Functions:

    • fetchActiveEnergy, fetchElevationData, fetchHeartRateData, fetchRouteData, fetchStepCount, and fetchFlightsClimbed: These helper methods retrieve detailed metrics for various workout activities.
    • fetchHeartRateTimeSeries: Gathers heart rate data over time for accurate visualization and analysis.
  5. Workout Activity Type Extension:

    • An extension on HKWorkoutActivityType has been added to map activity types to user-friendly names for display purposes.

Impact:

This enhancement enables PWAs to leverage HealthKit’s fitness data, making it possible to integrate rich health insights into the web-based app. Users can view their fitness metrics within the PWA interface.

haszz avatar Oct 27 '24 11:10 haszz