This assumes you have finished Install & Configure
and added the companion watch app.
The complete example
Registration
SamplingPackageRegistry().register(AppleWatchSamplingPackage()) makes the nine
watch measure types and the AppleWatchDevice known to CAMS.Watch as a connected device
The watch is connected to the phone and the phone is the primary device that runs
the study and uploads the data, and the watch is a peripheral that sends data to it.
Watch configuration
Sampling rates and which sensors run are properties of the
AppleWatchDevice, not
of the individual Measure. See
Configuring the Watch.Add measures
phone, the files still arrive from the watch but
nothing is converted into measurements.Note
fileTransferInterval (why your data is 15 minutes old)
fileTransferInterval (why your data is 15 minutes old)
The watch buffers records locally and hands them over on a timer. With the default
of 15 minutes, a measurement collected at 10:00 reaches your app around 10:15,
together with everything else from that quarter hour.Lower the interval for faster data transfer but cause fast battery drain.
backgroundSessionType (how the watch keeps collecting)
backgroundSessionType (how the watch keeps collecting)
watchOS suspends an app shortly after the wrist is lowered, unless it holds a
background runtime session. The default,
microphone, starts a silent capture
session that keeps the watch app alive without registering a workout.The alternative, workout, runs longer and more reliably but appears in the
participant’s fitness apps and affects their activity rings. This solution can
result in app store rejection.Status of the Watch
TheAppleWatchDeviceManager holds the live state of the watch connection. Whether a
watch is paired, if the companion app is installed, and how transfers are going:
On the Watch App
1
Open app and press Start
watchOS will not run a freshly installed app in the background before its first launch.
2
Grant the permissions
HealthKit for heart rate, microphone for sound. The prompts appear on the watch.
3
Check the status
AppleWatchStatus reports paired: true, appInstalled: true, collecting: true.4
First transfer
Wait up to
fileTransferInterval to check for the first transfer.
Press Send data to phone on the watch to skip the wait while testing.