iOS (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 benilif 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.
func connectDevice(_ device: Device, _ connectionCallback: @escaping(Bool) -> Void)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
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 forisPairedstate changes.isAppInstalledListener: callback function forisWatchAppInstalledstate changes.isComplicationEnabledListener: callback function forisComplicationEnabledstate changes.
Recording session management
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
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?