apple-wholeiOS (Swift)

iOS Functions

Initialization of Terra manager

TerraRT

Initializes the TerraRT instance with the provided developer ID and an optional reference ID.

init(devId: Swift.String, referenceId: Swift.String?, completion: @escaping (Swift.Bool) -> Swift.Void)
  • devId: The developer ID used to authenticate and initialize TerraRT.

  • referenceId: An optional reference ID for the initialization. Can be nil if not needed.

  • completion: A closure that returns a Bool, indicating success (true) or failure (false) of the initialization.

Returns: An instance of TerraRT and executes the completion handler with the result of the initialization (success/failure).

Connection Setup

connectDevice

Connects to a Device.

func connectDevice(_ device: Device, _ connectionCallback: @escaping(Bool) -> Void)
  • device: A device object returned from startBluetoothScan.

  • connectionCallback: A completion function called when the connection is completed.

initConnection

Initialises a user with the Terra backend

  • token: An authentication token.

  • completion: A completion function called when the initialisation is complete.

disconnect

Disconnects from a connection.

  • type: Enum representing the connection to disconnect from.

startBluetoothScan

Starts a Bluetooth scan session

Data Streaming

startRealtime

Starts streaming data for a given Connection type

  • type: Enum representing the connection to make.

  • dataType: Enum set of the data types to stream.

  • token: A user token for authentication.

  • callback: A callback for data reception.

  • connectionCallback: A callback for connection success.

stopRealtime

Stops streaming for a given connection type


iOS -> WatchOS Functions

circle-info

The functions outlined in this section are only to be used in conjunction with an app running on watchOS, which uses the WatchOS Functions

Connection management

connectWithWatchOS

Initialise a connection with an Apple Watch

throws TerraError.FeatureNotSupported

setWatchOSConnectionStateListener

Sets a listener for changes in ConnectionState

  • listener: A listener function called depending on the state of the watch connection.

setWatchStateChangeListeners

Set watch state change listeners (for isPaired, isWatchAppInstalled, and isComplicationEnabled fields)

  • isPairedListener: callback function for isPaired state changes.

  • isAppInstalledListener: callback function for isWatchAppInstalled state changes.

  • isComplicationEnabledListener: callback function for isComplicationEnabled state changes.

Recording session management

circle-info

The functions below are to be used to manage sessions started on the WatchOS app, using startExercise

resumeWatchOSWorkout

Resume a workout if it is going on

pauseWatchOSWorkout

Pauses a workout if it is going on

stopWatchOSWorkout

Stops a workout if it is going on

Messaging

setMessageHandler

Set a message handler to handle the custom message sent from sendMessage function

sendMessage

Send a message to the iOS Companion App

  • data: A dictionary of data to send to iOS Companion app.


WatchOS Functions

Initialization

circle-info

All functions below are to be called on an instance of the Terra class after it has been initialized (no input parameters)

Connection Setup

sharingDataAuthorised

Returns Bool depicting if user has granted writing Workout information to HealthKit.

connect

Connect to iOS companion app

setWatchOSConnectionStateListener

Set a listener for changes in ConnectionState

  • listener: A listener function called depending on the state of the watch connection.

Data Streaming

startStream

Start observing for different data types and stream it to the iOS companion app

  • dTypes: A set of all the types to start observing for.

  • completion: Completion function indicating if the stream started successfully.

stopStream

Stop streaming to the iOS Companion app

setUpdateHandler (WatchOS)

Set an update handler to receive data on the Watch App. Will only be triggered if startStream has been called

Recording Session Management

startExercise

Starts an exercise (HKWorkout) and streams to iOS Companion

  • workoutType: The workout type Enum to start exercise for.

  • completion: Completion function indicating if the exercise started correctly.

pauseExercise

Pause the current running exercise session

resumeExercise

Resumes a paused exercise session

stopExercise

Stop the exercise (if one has been started)

setWorkoutStateListener

Set an update handler to receive updates on the state of the workout. Useful when workout is paused/managed from the iOS app side


Messaging

setMessageHandler (WatchOS)

Set a message handler to handle the custom message sent from sendMessage function

sendMessage (WatchOS)

Send a message to the iOS Companion App

  • data: A dictionary of data to send to iOS Companion app.

Was this helpful?