Guides

Setup Project

Learn how to setup your mobile project for compatibility with the Sahha SDK

Choose your platform:


iOS

Follow these steps to setup your iOS project:


Step 1) Enable HealthKit

Before you can connect to Apple Health, you must enable the HealthKit capabilities for your app.

You add capabilities to your app using the Signing & Capabilities pane of the project editor.

Add `HealthKit` entitlement to your Xcode project

  • Select your App Target in the Project panel
  • Select Signing & Capabilities
  • Tap the + button
  • Select HealthKit from the list
  • Double-click the capability to add it to your project

Step 1.1

In the Project navigator of the main window, select the project — the root group with the same name as your app — and in the project editor that appears, select the appropriate target and then click the Signing & Capabilities tab.

Using HealthKit


Step 1.2

In the toolbar, click the Library button (+) to open the Capabilities library. Alternatively, click + Capability to the left of the build configurations, or choose Editor > Add Capability. The Capabilities library displays only the capabilities available to the target platform and your program membership. Select a capability in the list to view its description on the right.

Using HealthKit


Step 1.3

Select HealthKit from the list of capabilities.

Using HealthKit


Step 1.4

After you add the HealthKit capability, Xcode links the HealthKit framework to your target and updates the target’s entitlements file to include the HealthKit Entitlement. If Xcode automatically manages the signing of your app, it also enables HealthKit for your app’s App ID.


Step 2) Background Delivery

In order for the Sahha SDK to passively collect health data, your app will need to enable background delivery for HealthKit.

Add `Background Delivery` capability to your Xcode project

To enable HealthKit run even while your app is in the background, perform the following:

  • Select your project in Xcode’s Project navigator.

  • Select the app’s target from the Targets list.

  • Click the Signing & Capabilities tab in the project editor.

  • Find the HealthKit capability.

  • Enable the nested Background Delivery capability.

Xcode adds the com.apple.developer.healthkit.background-delivery entitlement to the target’s entitlements file.

Using HealthKit


Step 3) Background Modes

In order for the Sahha SDK to send health data to the Sahha API even while your app is in the background, you will need to enable the background modes capability.

You add capabilities to your app using the Signing & Capabilities pane of the project editor.

Add `Background Modes` entitlement to your Xcode project

  • Select your App Target in the Project panel
  • Select Signing & Capabilities
  • Tap the + button
  • Select Background Modes from the list
  • Set Background Fetch to true
  • Set Background Processing to true

Step 3.1

In the Project navigator of the main window, select the project — the root group with the same name as your app — and in the project editor that appears, select the appropriate target and then click the Signing & Capabilities tab.

Using HealthKit


Step 3.2

In the toolbar, click the Library button (+) to open the Capabilities library. Alternatively, click + Capability to the left of the build configurations, or choose Editor > Add Capability. The Capabilities library displays only the capabilities available to the target platform and your program membership. Select a capability in the list to view its description on the right.

Using HealthKit


Step 3.3

Select Background Modes from the list of capabilities.

Using HealthKit

Xcode adds the UIBackgroundModes array to your app’s Info.plist file, if it isn’t already present, and uses the modes you select to populate the array with the necessary values.


Step 3.4

In the Signing & Capabilities tab of the Project Navigator, select these values under the Background Modes capability:

  • Background Fetch
  • Background processing

Using HealthKit


Step 3) Add Usage Descriptions

HealthKit uses a fine-grained authorization mechanism to help protect the user’s privacy; your app must request permission to read and, optionally, write each individual sample type it supports.

Before prompting the user for their permission, you must configure your app to include one or more purpose strings, which accurately and concisely describe why the app needs to read the user’s health data, write health data to their HealthKit store, or both. The presence of these purpose strings is an App Store requirement for any app that integrates with HealthKit. The system displays this information to the user when requesting their permission, along with the specific sample types that your app needs to access, which helps them make an informed decision.

You will need to write a message explaining to the user why they should approve these permissions.

Add usage descriptions to your Xcode project

Follow these steps to add the usage description for reading health data to your app’s target:

  • Select your App Target in the Project panel
  • Select Info
  • Tap the + button to add a new key
  • Choose Privacy - Health Share Usage Description.
  • Write a clear description for the key value such as This app needs your health info to deliver mood predictions.

Using HealthKit


Android

Follow these steps to setup your Android project:


Step 1) Edit your AndroidManifest

In order to access your user's device sensors, you will need to include the correct uses-permission values in your project's AndroidManifest.xml.

Choose your framework to follow the correct steps:

Step 1) Find the project’s AndroidManifest.xml file. This is located in the project’s app/src/main folder.

Android Manifest

Step 2) Within the file, declare the permissions between the manifest and application code.

Android Manifest

Step 3) Here is an example declaring Heart and Activity permissions. Make sure to save the file!

Android Manifest


Step 2) Review Sensor Permissions

Each sensor has a set of associated user-permission values. You can see the full list below.

<!-- AndroidManifest.xml -->
<!-- Heart -->
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
<!-- Blood -->
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
<!-- Sleep -->
<uses-permission android:name="android.permission.health.READ_SLEEP" />
<!-- Activity -->
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
<!-- Oxygen -->
<uses-permission android:name="android.permission.health.READ_VO2_MAX" />
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
<!-- Energy -->
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
<!-- Body -->
<uses-permission android:name="android.permission.health.READ_BODY_FAT" />
<uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS" />
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />
<uses-permission android:name="android.permission.health.READ_BONE_MASS" />
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
<!-- Temperature -->
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
<uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />
<!-- Exercise -->
<uses-permission android:name="android.permission.health.READ_EXERCISE" />

Device Sensor

Please note SahhaSensor.device does not require any AndroidManifest.xml permission declarations.


Step 3) Choose your Sensors

Add each set of uses-permission values for each required sensor to your project's AndroidManifest.xml.

Choosing Sensor Permissions

For example, if your project requires the Heart and Sleep sensors, then included the following uses-permission values:

"READ_HEART_RATE"

"READ_HEART_RATE_VARIABILITY"

"READ_RESTING_HEART_RATE"`

"READ_SLEEP"

<!-- AndroidManifest.xml -->
<manifest ... >
<!-- Heart -->
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
<!-- Sleep -->
<uses-permission android:name="android.permission.health.READ_SLEEP" />
<application ... >
...
<application ... />
<manifest ... />

Step 4) Configure your Sensors

Configuring Sensors

After including the uses-permission values for each required sensor in your AndroidManifest.xml, you will also need to configure the same sensor values via the Sahha.configure method.

View the SDK Configure documentation .

If the values do not match, you are likely to receive build errors and risk your app being rejected on the Google Play Store!

Previous
SDK