Device Data

Since Sahha requires device data (such as steps, sleep and other data) in order to analyse health, we need to access the devices sensors. This guide will show you how to configure, and manage device sensors and the data they collect.

The Sahha SDK handles device sensors for your app and acts as a bridge between your app and the device sensors. This simplifies the process of collecting and analyzing device data.

About the device sensor status

The sensors have multiple possible statuses which indicate whether they are enabled or disabled or anywhere in between.

enum class SahhaSensorStatus {
pending, // Sensors pending User permission
unavailable, // Sensors not supported by the User's device
disabled, // Sensors disabled by the User
enabled // Sensors enabled by the User

(iOS) Permission Privacy - IMPORTANT INFO

Apple limits the ability to detect the true sensor status to protect user privacy.

Apple documentation:

To help protect the user’s privacy, your app doesn’t know whether the user granted or denied permission to read data from HealthKit. If the user denied permission, attempts to query data from HealthKit return only samples that your app successfully saved to the HealthKit store.

This means that if a Sensor is available, the only possible SensorStatus is:

  • pending if you have not already prompted the user for permission yet
  • enabled if you have already prompted the user for permission

The disabled SensorStatus is not triggered even if the user declines permission.

The disabled SensorStatus is only included in the iOS SDK to keep parity with the Android SDK.

Please read the official Apple documentation to better understand authorizing access to health data for iOS.

Authorizing access to health data for iOS

Getting the device sensor status

You can check the current status of the sensors by calling getSensorStatus. This method is asynchronous and will return the updated SahhaSensorStatus in its callback.

Configure the SDK before you Get Sensor Status

On app launch, SensorStatus will always be pending. You must configure the SDK before you can get the correct SensorStatus.

We suggest calling getSensorStatus in the callback of configure.

Sahha.configure(application, settings) { error, success ->
if (error != null) {
} else {
Sahha.getSensorStatus(this@MainActivity) { error, sensorStatus ->
if (error != null) {
} else {

Enabling device sensors

Before the SDK can start collecting data, you will need to enable sensors by calling enableSensors. This method is asynchronous and will return the updated SahhaSensorStatus in its callback.

Sahha.enableSensors(this@MainActivity) { error, sensorStatus ->
if (error != null) {
} else {

(iOS) Sleep Sensor - IMPORTANT INFO

Setup Sleep Before Using the SDK

In order for the Sahha SDK to collect data from the sleep sensor, Sleep functionality must be enabled by your mobile user BEFORE calling enableSensors.

We suggest checking if your user has seen the HealthKit permission screen before enabling the sleep sensor. If the status is pending, this is the perfect time to show your custom UI asking your user to setup Sleep in the Health App.

Please read the official Apple documentation to help your users setup Sleep for iOS.

Sleep for iOS

Open App Settings

It's possible for your app user to disable a sensor. In this case, you must send the user to the app settings to manually enable the sensor.


(iOS) Permission Changes - IMPORTANT INFO

App will terminate if Permission Changes

If the user enables / disables a sensor permission from the device settings menu while your app is in the background, the iOS system will force your app to terminate. This is intentional behavior and your app will need to be relaunched.