From apple-kit-skills
Access research-grade sensor data from iOS/watchOS for approved studies, including ambient light, motion, device usage, keyboard metrics, and health sensors.
How this skill is triggered — by the user, by Claude, or both
Slash command
/apple-kit-skills:sensorkitThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Collect research-grade sensor data from iOS and watchOS devices for approved
Collect research-grade sensor data from iOS and watchOS devices for approved research studies. SensorKit provides access to ambient light, motion, device usage, keyboard metrics, visits, phone/messaging usage, speech metrics, face metrics, wrist temperature, heart rate, ECG, and PPG data. Targets Swift 6.3 / iOS 26+.
SensorKit is restricted to Apple-approved research studies. Apps must submit
a research proposal to Apple and receive the com.apple.developer.sensorkit.reader.allow
entitlement before any sensor data is accessible. This is not a general-purpose
sensor API -- use CoreMotion for ordinary accelerometer, gyroscope, pedometer,
or activity-recognition 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:
<key>com.apple.developer.sensorkit.reader.allow</key>
<array>
<string>ambient-light-sensor</string>
<string>motion-accelerometer</string>
<string>motion-rotation-rate</string>
<string>device-usage</string>
<string>keyboard-metrics</string>
<string>messages-usage</string>
<string>phone-usage</string>
<string>visits</string>
<string>pedometer</string>
<string>on-wrist</string>
<string>speech-metrics-siri</string>
<string>speech-metrics-telephony</string>
<string>ambient-pressure</string>
<string>ecg</string>
<string>ppg</string>
</array>
Verify newer or specialized sensors against their individual SRSensor pages.
For example, Apple's ECG and PPG sensor pages explicitly require ecg and
ppg entitlement values in addition to their NSSensorKitUsageDetail entries.
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:
<!-- Study purpose shown in the authorization sheet -->
<key>NSSensorKitUsageDescription</key>
<string>This study monitors activity patterns for sleep research.</string>
<!-- Link to your study's privacy policy -->
<key>NSSensorKitPrivacyPolicyURL</key>
<string>https://example.com/privacy-policy</string>
<!-- Per-sensor usage explanations -->
<key>NSSensorKitUsageDetail</key>
<dict>
<key>SRSensorUsageMotion</key>
<dict>
<key>Description</key>
<string>Measures physical activity levels during the study.</string>
<key>Required</key>
<true/>
</dict>
<key>SRSensorUsageAmbientLightSensor</key>
<dict>
<key>Description</key>
<string>Records ambient light to assess sleep environment.</string>
</dict>
</dict>
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. Examples:
motion sensors use SRSensorUsageMotion, ambient pressure uses SRSensorUsageElevation,
ECG uses SRSensorUsageECG, PPG uses SRSensorUsagePPG, heart rate uses
SRSensorUsageHeartRate, and wrist temperature uses SRSensorUsageWristTemperature.
Request authorization for the sensors your study needs. The system shows the Research Sensor & Usage Data sheet on first request.
import SensorKit
let reader = SRSensorReader(sensor: .ambientLightSensor)
// Request authorization for multiple sensors at once
SRSensorReader.requestAuthorization(
sensors: [.ambientLightSensor, .accelerometer, .keyboardMetrics]
) { error in
if let error {
print("Authorization request failed: \(error)")
}
}
Check a reader's current status before recording:
switch reader.authorizationStatus {
case .authorized:
reader.startRecording()
case .denied:
// User declined -- direct to Settings > Privacy > Research Sensor & Usage Data
break
case .notDetermined:
// Request authorization first
break
@unknown default:
break
}
Monitor status changes through the delegate:
func sensorReader(_ reader: SRSensorReader, didChange authorizationStatus: SRAuthorizationStatus) {
switch authorizationStatus {
case .authorized:
reader.startRecording()
case .denied:
reader.stopRecording()
default:
break
}
}
| Sensor | Type | Sample Type |
|---|---|---|
.deviceUsageReport | Device usage | SRDeviceUsageReport |
.keyboardMetrics | Keyboard activity | SRKeyboardMetrics |
.onWristState | Watch wrist state | SRWristDetection |
.acousticSettings | Acoustic/accessibility settings | SRAcousticSettings |
| Sensor | Type | Sample Type |
|---|---|---|
.messagesUsageReport | Messages app usage | SRMessagesUsageReport |
.phoneUsageReport | Phone call usage | SRPhoneUsageReport |
| Sensor | Type | Sample Type |
|---|---|---|
.accelerometer | Acceleration data | [CMRecordedAccelerometerData] |
.rotationRate | Rotation rate | [CMRecordedRotationRateData] |
.pedometerData | Step/distance data | CMPedometerData |
.visits | Visited locations | SRVisit |
.mediaEvents | Media interactions | SRMediaEvent |
.faceMetrics | Face expressions | SRFaceMetrics |
.heartRate | Heart rate | CMHighFrequencyHeartRateData |
.odometer | Speed/slope | CMOdometerData |
.siriSpeechMetrics | Siri speech | SRSpeechMetrics |
.telephonySpeechMetrics | Phone speech | SRSpeechMetrics |
.wristTemperature | Wrist temp (sleep) | SRWristTemperatureSession |
.sleepSessions | Sleep session summaries | SRSleepSession |
.photoplethysmogram | PPG stream | [SRPhotoplethysmogramSample] |
.electrocardiogram | ECG stream | [SRElectrocardiogramSample] |
| Sensor | Type | Sample Type |
|---|---|---|
.ambientLightSensor | Ambient light | SRAmbientLightSample |
.ambientPressure | Pressure/temp | [CMRecordedPressureData] |
SRSensorReader is the central class for accessing sensor data. Each instance
reads from a single sensor.
import SensorKit
// Create a reader for one sensor
let lightReader = SRSensorReader(sensor: .ambientLightSensor)
let keyboardReader = SRSensorReader(sensor: .keyboardMetrics)
// Assign delegate to receive callbacks
lightReader.delegate = self
keyboardReader.delegate = self
The reader communicates entirely through SRSensorReaderDelegate:
| Delegate Method | Purpose |
|---|---|
sensorReader(_:didChange:) | Authorization status changed |
sensorReaderWillStartRecording(_:) | Recording is about to start |
sensorReader(_:startRecordingFailedWithError:) | Recording failed to start |
sensorReaderDidStopRecording(_:) | Recording stopped |
sensorReader(_:stopRecordingFailedWithError:) | Recording failed to stop |
sensorReader(_:didFetch:) | Devices fetched |
sensorReader(_:fetchDevicesDidFailWithError:) | Device fetch failed |
sensorReader(_:fetching:didFetchResult:) | Sample received |
sensorReader(_:didCompleteFetch:) | Fetch completed |
sensorReader(_:fetching:failedWithError:) | Fetch failed |
// Begin recording -- sensor stays active as long as any app has a stake
reader.startRecording()
// Stop recording -- framework deactivates the sensor when
// no app or system process is using it
reader.stopRecording()
Build an SRFetchRequest with a time range and target device, then pass it to
the reader:
let request = SRFetchRequest()
request.device = SRDevice.current
request.from = SRAbsoluteTime(CFAbsoluteTimeGetCurrent() - 86400 * 2) // 2 days ago
request.to = SRAbsoluteTime.current()
reader.fetch(request)
Receive results through the delegate:
func sensorReader(
_ reader: SRSensorReader,
fetching request: SRFetchRequest,
didFetchResult result: SRFetchResult<AnyObject>
) -> Bool {
let timestamp = result.timestamp
switch reader.sensor {
case .ambientLightSensor:
if let sample = result.sample as? SRAmbientLightSample {
let lux = sample.lux
let chromaticity = sample.chromaticity
let placement = sample.placement
processSample(lux: lux, chromaticity: chromaticity, at: timestamp)
}
case .keyboardMetrics:
if let sample = result.sample as? SRKeyboardMetrics {
let words = sample.totalWords
let speed = sample.typingSpeed
processKeyboard(words: words, speed: speed, at: timestamp)
}
case .deviceUsageReport:
if let sample = result.sample as? SRDeviceUsageReport {
let wakes = sample.totalScreenWakes
let unlocks = sample.totalUnlocks
processUsage(wakes: wakes, unlocks: unlocks, at: timestamp)
}
default:
break
}
return true // Return true to continue receiving results
}
func sensorReader(_ reader: SRSensorReader, didCompleteFetch request: SRFetchRequest) {
print("Fetch complete for \(reader.sensor)")
}
func sensorReader(
_ reader: SRSensorReader,
fetching request: SRFetchRequest,
failedWithError error: any Error
) {
print("Fetch failed: \(error)")
}
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.
// Get the current device
let currentDevice = SRDevice.current
print("Model: \(currentDevice.model)")
print("System: \(currentDevice.systemName) \(currentDevice.systemVersion)")
// Fetch all available devices for a sensor
reader.fetchDevices()
Handle fetched devices through the delegate:
func sensorReader(_ reader: SRSensorReader, didFetch devices: [SRDevice]) {
for device in devices {
let request = SRFetchRequest()
request.device = device
request.from = SRAbsoluteTime(CFAbsoluteTimeGetCurrent() - 86400)
request.to = SRAbsoluteTime.current()
reader.fetch(request)
}
}
func sensorReader(_ reader: SRSensorReader, fetchDevicesDidFailWithError error: any Error) {
print("Failed to fetch devices: \(error)")
}
| 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 |
// WRONG -- fails at runtime with SRError.invalidEntitlement
let reader = SRSensorReader(sensor: .ambientLightSensor)
reader.startRecording()
// CORRECT -- obtain entitlement from Apple first, configure manual
// provisioning profile, then use SensorKit
// WRONG -- fetching data recorded moments ago returns nothing
reader.startRecording()
// ... record for a few minutes ...
let request = SRFetchRequest()
request.from = SRAbsoluteTime(CFAbsoluteTimeGetCurrent() - 300)
request.to = SRAbsoluteTime.current()
reader.fetch(request) // Empty results due to 24-hour hold
// CORRECT -- fetch data that is at least 24 hours old
request.from = SRAbsoluteTime(CFAbsoluteTimeGetCurrent() - 86400 * 3)
request.to = SRAbsoluteTime(CFAbsoluteTimeGetCurrent() - 86400)
reader.fetch(request)
// WRONG -- no delegate means no callbacks, results are silently lost
let reader = SRSensorReader(sensor: .accelerometer)
reader.startRecording()
reader.fetch(request)
// CORRECT -- assign delegate first
reader.delegate = self
reader.startRecording()
reader.fetch(request)
// WRONG -- missing NSSensorKitUsageDetail for the sensor
// Authorization sheet shows no explanation, user is less likely to approve
// CORRECT -- add usage detail for every sensor you request
// See Info.plist Configuration section above
// WRONG -- generic error handling
func sensorReader(_ reader: SRSensorReader, fetching: SRFetchRequest, failedWithError error: any Error) {
print("Error")
}
// CORRECT -- handle specific error codes
func sensorReader(_ reader: SRSensorReader, fetching: SRFetchRequest, failedWithError error: any Error) {
if let srError = error as? SRError {
switch srError.code {
case .invalidEntitlement:
// Entitlement missing or sensor not in entitlement array
break
case .noAuthorization:
// User has not authorized this sensor
break
case .dataInaccessible:
// Data in 24-hour holding period or otherwise unavailable
break
case .fetchRequestInvalid:
// Invalid time range or device
break
case .promptDeclined:
// User declined the authorization prompt
break
@unknown default:
break
}
}
}
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 stopnpx claudepluginhub dpearson2699/swift-ios-skills --plugin all-ios-skillsReads, writes, and queries Apple Health data via HealthKit, including HKHealthStore authorization, sample/statistics queries, background delivery, and workout sessions.
Generates cross-platform health data queries, writes health metrics, and monitors real-time health changes via Shiny Health for Apple HealthKit and Android Health Connect.
References HealthKit APIs for querying HKHealthStore, HKQuantitySample, workouts, and health data read/write operations in iOS apps.