iOS (Swift)
iOS Functions
Initialization of Terra manager
TerraRT
Initializes the TerraRT instance with the provided developer ID and an optional reference ID.
devId
: The developer ID used to authenticate and initialize TerraRT.referenceId
: An optional reference ID for the initialization. Can benil
if not needed.completion
: A closure that returns aBool
, 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
.
device
: A device object returned fromstartBluetoothScan
.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
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 forisPaired
state changes.isAppInstalledListener
: callback function forisWatchAppInstalled
state changes.isComplicationEnabledListener
: callback function forisComplicationEnabled
state changes.
Recording session management
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
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?