npx skills add ...
npx skills add dpearson2699/swift-ios-skills --skill sensorkit
Access research-grade sensor data using SensorKit for approved studies. Use when an app needs SensorKit entitlement setup, Research Sensor & Usage Data authorization, ambient light, recorded motion, device usage, keyboard metrics, visits, speech, face, wrist temperature, ECG, PPG, acoustic settings, or sleep-session data. Route ordinary motion to CoreMotion and health records/workouts to HealthKit.
npx skills add dpearson2699/swift-ios-skills --skill sensorkit
Choose the exact SRSensor and verify its individual availability. Use
CoreMotion for ordinary motion/activity features and HealthKit for health
records and workouts.
SensorKit enables research apps to record and fetch sensor data across iPhone and Apple Watch. The framework requires:
com.apple.developer.sensorkit.reader.allow
only for approved studies.An app can access up to 7 days of prior recorded data for an active sensor.
Add the SensorKit reader entitlement to a .entitlements file. List only the
sensors Apple approved for the study. Common entitlement values include:
Load the Entitlement and Usage-Detail Catalog
when selecting the exact entitlement string and NSSensorKitUsageDetail key
for each approved sensor. Recheck specialized sensors against their individual
SRSensor pages.
For manual signing, set Code Signing Entitlements to the entitlements file,
Code Signing Identity to Apple Developer, Code Signing Style to Manual,
and Provisioning Profile to the explicit profile with SensorKit capability.
Three keys are required:
If Required is true and the user denies that sensor, the system warns them
that the study needs it and offers a chance to reconsider.
Use the exact usage-detail dictionary for each requested sensor. Load the Entitlement and Usage-Detail Catalog when mapping sensors beyond the motion and ambient-light examples above.
Request authorization for the sensors your study needs. The system shows the Research Sensor & Usage Data sheet on first request.
Use one status handler both for the initial check and delegate changes:
Load the Sensor Catalog to map
each SRSensor to its sample type. Request only sensors approved for the study
and recheck the selected sensor's availability and usage-detail key.
SRSensorReader is the central class for accessing sensor data. Each instance
reads from a single sensor.
The reader communicates through SRSensorReaderDelegate. Load the
Delegate Method Catalog
when wiring the complete authorization, recording, device-fetch, and
sample-fetch lifecycle.
Build an SRFetchRequest with a time range and target device, then pass it to
the reader:
Receive results through the delegate:
Cast result.sample to the sample shape for the reader's sensor. Some streams
return one object per result, while recorded motion, ECG, PPG, and ambient
pressure streams can return arrays of recorded samples.
SensorKit imposes a 24-hour holding period on newly recorded data. Fetch requests whose time range overlaps this period return no results. Design data collection workflows around this delay.
SRDevice identifies the hardware source for sensor samples. Use it to
distinguish data from iPhone versus Apple Watch.
Handle fetched devices through the delegate:
| Property | Type | Description |
|---|---|---|
model | String | User-defined device name |
name | String | Framework-defined device name |
systemName | String | OS name (iOS, watchOS) |
systemVersion | String | OS version |
productType | String | Hardware identifier |
current | SRDevice | Class property for the running device |
Obtain Apple's study approval, the sensor-specific entitlement values, and a matching manual provisioning profile before constructing production readers.
Apply the Data Holding Period; a fetch overlapping the hold is not proof that recording failed.
Assign the delegate before startRecording() or fetch(_:); results and
failures arrive through delegate callbacks.
Add the exact Info.plist Configuration usage-detail entry for every requested sensor.
Distinguish at least .invalidEntitlement, .noAuthorization,
.dataInaccessible, .fetchRequestInvalid, .promptDeclined, and unknown
future codes. Load the Full Delegate Implementation
for the complete switch and callback wiring.
com.apple.developer.sensorkit.reader.allow entitlement lists only needed sensorsNSSensorKitUsageDescription in Info.plist with clear study purposeNSSensorKitPrivacyPolicyURL in Info.plist with valid privacy policy URLNSSensorKitUsageDetail entries for every requested sensorRequired key set appropriately for essential vs. optional sensorsstartRecording() or fetch(_:)SRError codes handled in all failure delegate methodsfetchDevices() used to discover available devices before fetchingstopRecording() called when data collection is completesensorReader(_:fetching:didFetchResult:) returns true to continue or false to stop