apple-wholeiOS (Swift)

SDK Installation

triangle-exclamation

Summary:

  1. In your info.plist, add:

    1. Privacy - Bluetooth Always Usage Description: Justification for BLE usage (shown to the user when requesting permission)

    2. Privacy - Motion Usage Description: Justification for phone motion sensor usage (shown to the user when requesting permission - only add if using phone sensors for streaming)

When the app is launched for the first time, these permissions will be requested from the user.


Connection setup/management

The SDK revolves around the TerraRT class, which manages Bluetooth connections and real-time data streaming.

SDK Initialization

circle-info

Always initialize the TerraRT class to begin using the SDK.

Do so every time the app is opened or brought into the foreground.

Initializing a Connection

Register the phone by calling initConnection.

This connects the phone to Terra, allows you to use other SDK functions, and allows it to be a producer once a wearable is connected later on.

To generate the token, make the below call from your backend

Connecting a device

iOS devices support connection via BLE or Apple Watch's WatchConnectivity protocol. For Apple Watch, refer to the WatchOS integration guide below.

The startBluetoothScan function returns a SwiftUI TerraBLEWidget view for device selection:


Streaming Real-Time Data

Once the phone is registered and you've connected a wearable, you can stream data from the wearable to your mobile app.

Start Streaming

Call startRealtime to stream data to your app locally (without sending to Terra's server):

To also send data to Terra's server, see the Your App → Terra guide.

Stop streaming and disconnect


WatchOS Integration

circle-info

To receive a data stream from an Apple Watch, the watch must be instructed to initiate a data stream to the iOS phone it is paired with.

For that, you'll need to have a WatchOS companion app running on the watch, which runs startStream or startExercise

Setup

  1. Create a WatchOS target within your iOS project:

    File -> New -> Target -> Watch App for iOS App.

  2. Enable HealthKit and Background Modes for the WatchOS app, and add the following privacy keys to your Info.plist:

    1. Privacy - Health Share Usage Description

    2. Privacy - Health Update Usage Description

    3. Privacy - Health Records Usage Description

Start Streaming from WatchOS

circle-info

Outside of a workout session, data recording frequency may be reduced. In order to capture data at the highest possible frequency, you'll want to start a workout session

On the iOS app, listen for updates from the WatchOS app using startRealtime with .WATCH_OS:


Streaming Workouts from WatchOS

The Apple Watch app can also manage a workout session, during which recording frequency is enhanced.

From the Watch: startExercise, stopExercise, pauseExercise, resumeExercise

From the iOS app: pauseWatchOSWorkout, resumeWatchOSWorkout, stopWatchOSWorkout

Last updated

Was this helpful?