Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactored Swift native implementation #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: health-13
Choose a base branch
from
Open

Conversation

iarata
Copy link
Contributor

@iarata iarata commented Apr 9, 2025

This PR refactors the Swift native implementation. It introduces the following new classes:

  • HealthDataWriter: writing health data to HealthKit functions
  • HealthDataReader: reading health data from HealthKit functions
  • HealthDataOperations: managing data permissions and delete functions
  • HealthConstants: constants used in the plugin (where types are introduced)
  • HealthUtilities: helper functions - also includes type conversion helpers for HKWorkoutActivityType

The initialisation of these classes are lazy now to help with performance.

In the new approach, when defining a new method for iOS native, for better error handling the cases should be handled as follow under the handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) function:

case "writeMeal":
   do {
         try healthDataWriter.writeMeal(call: call, result: result)
    } catch {
         result(FlutterError(code: "WRITE_ERROR",
                    message: "Error writing meal: \(error.localizedDescription)",
                    details: nil))
    }

This now requires each new method to throw an error in case of failure.

Supported error codes to be used:

  • REQUEST_AUTH_ERROR: Error requesting authorisation
  • PERMISSION_ERROR: Error checking permissions
  • WRITE_ERROR: Error writing [DataType]
  • DELETE_ERROR: Error deleting data
  • ARGUMENT_ERROR: Missing required argument
  • INVALID_TYPE: Invalid dataTypeKey
  • HEALTH_ERROR: Error getting health data
  • INTERNAL_ERROR: Internal instance reference lost
  • STATISTICS_ERROR: Error getting statistics
  • STEPS_ERROR: Error getting step count

@iarata iarata requested review from bardram and Panosfunk April 9, 2025 08:14
@iarata iarata self-assigned this Apr 9, 2025
@iarata
Copy link
Contributor Author

iarata commented Apr 30, 2025

Only files under packages/health/* are relevant. The rest of the changes are the synced contributions to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant