Skip to main content
Version: 1.0

GDScript API

The plugin provides a GDScript wrapper named HealthKit, which is automatically registered as an Autoload singleton when the plugin is enabled. It handles platform checks and provides mock data for non-iOS platforms.

Singleton: HealthKit

func _ready() -> void:
# Connect to signals
HealthKit.permission_result.connect(_on_permission_result)
HealthKit.steps_updated.connect(_on_steps_updated)

# Request permission
HealthKit.request_permission()

# Check permission and availability
var is_available: bool = HealthKit.is_health_data_available()
var status: int = HealthKit.get_permission_status()

# Start real-time observer and background delivery
HealthKit.start_step_observer()

# Async snapshot queries (call first, then read result after ~1s)
HealthKit.run_today_steps_query()
HealthKit.run_total_steps_query()
HealthKit.run_period_steps_query(7) # last 7 days

# Read cached results
var today: int = HealthKit.get_today_steps()
var total: int = HealthKit.get_total_steps()
var period: Dictionary = HealthKit.get_period_steps_dict() # {"2026-03-15": 5432, ...}

Signals

SignalDescription
permission_result(granted: bool)Emitted after request_permission() completes.
steps_updated(steps: int)Emitted when HKObserverQuery detects a change in today's step count.
today_steps_ready(steps: int)Emitted when run_today_steps_query() completes.
total_steps_ready(steps: int)Emitted when run_total_steps_query() completes.
period_steps_ready(steps_dict: Dictionary)Emitted when run_period_steps_query() completes.
pedometer_steps_updated(steps: int)Emitted when the real-time pedometer detects new steps since it was started.
pedometer_error(reason: String)Emitted if the pedometer encounters an error.

Methods

MethodReturnsDescription
request_permission()voidRequests permission to read HealthKit data.
get_permission_status()intReturns the AuthorizationStatus.
get_permission_status_string(status: int)StringReturns a human-readable string for the given AuthorizationStatus.
is_health_data_available()boolChecks if HealthKit is available on the device.
start_step_observer()voidStarts background observation for step count changes.
stop_step_observer()voidStops background step observation.
is_pedometer_available()boolChecks if the device supports CMPedometer.
get_pedometer_permission_status()intReturns the MotionAuthorizationStatus.
start_pedometer_observer()voidStarts real-time pedometer tracking.
stop_pedometer_observer()voidStops real-time pedometer tracking.
get_live_pedometer_steps()intReturns the number of steps tracked since the pedometer was started.
run_today_steps_query()voidRequests the total step count for today. Emits today_steps_ready when done.
get_today_steps()intReturns the cached step count for today (after query finishes).
run_total_steps_query()voidRequests the all-time total step count. Emits total_steps_ready when done.
get_total_steps()intReturns the cached all-time step count (after query finishes).
run_period_steps_query(days: int)voidRequests daily step counts for the past days. Emits period_steps_ready.
get_period_steps_dict()DictionaryReturns the cached dictionary of period steps.
open_settings()voidOpens the app settings.

Enums

AuthorizationStatus (HealthKit)

  • NOT_DETERMINED = 0
  • SHARING_DENIED = 1
  • SHARING_AUTHORIZED = 2

MotionAuthorizationStatus (CoreMotion)

  • NOT_DETERMINED = 0
  • RESTRICTED = 1
  • DENIED = 2
  • AUTHORIZED = 3