Access ambient, motion, biometric, and interaction research data using SensorKit. Use when configuring sensor readers, handling authorization and study onboarding, fetching sample streams, managing user data deletion, or building research and clinical studies.
87%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Access granular ambient, motion, biometric, and interaction sensor streams for approved research and clinical studies using SRSensorReader. Targets Swift 6.4 / iOS 26+.
Entitlement Warning: SensorKit requires Apple entitlement approval (
com.apple.developer.sensorkit.reader.allow). SensorKit cannot be tested on standard consumer apps or simulators without approved research provisioning.
com.apple.developer.sensorkit.reader.allow from Apple.NSSensorKitUsageDescription, NSSensorKitUsageDescriptionAmbientLightSensor).import SensorKit
func requestSensorAccess(for sensors: Set<SRSensor>) async {
let status = await SRSensorReader.requestAuthorization(for: sensors)
// Handle authorization response
}Create an SRSensorReader per sensor type and assign an SRSensorReaderDelegate:
final class AmbientLightCollector: NSObject, SRSensorReaderDelegate {
private let reader = SRSensorReader(sensor: .ambientLightSensor)
override init() {
super.init()
reader.delegate = self
}
func start() {
guard reader.authorizationStatus == .authorized else { return }
reader.startRecording()
}
func stop() {
reader.stopRecording()
}
}Query historical recorded samples by date interval:
func fetchSamples(from start: SRAbsoluteTime, to end: SRAbsoluteTime) {
let request = SRFetchRequest()
request.from = start
request.to = end
reader.fetch(request)
}
// SRSensorReaderDelegate
func sensorReader(_ reader: SRSensorReader, fetching request: SRFetchRequest, didFetchResult result: SRFetchResult) -> Bool {
if let sample = result.sample as? SRAmbientLightSample {
// Process sensor sample
}
return true // Return true to continue fetching remaining results
}
func sensorReader(_ reader: SRSensorReader, didCompleteFetch request: SRFetchRequest) {
// Finished fetch
}.ambientLightSensor, .accelerometer, .rotationRate, .elevation..keyboardMetrics, .deviceUsageReport, .messagesUsageReport, .phoneUsageReport..speechMetrics, .faceMetrics, .wristTemperature, .heartRate.Research participants can delete recorded data. Honor deletion requests via SRSensorReader:
func purgeData(before timestamp: SRAbsoluteTime) async throws {
let request = SRDeletionRequest()
request.endTime = timestamp
try await reader.delete(request)
}false from didFetchResult halts subsequent sample delivery.SRFetchRequest to bounded start and end timestamps to avoid memory exhaustion.com.apple.developer.sensorkit.reader.allow entitlement confirmed activerequestAuthorization(for:) called before starting reader recordingdidFetchResult returns true while iterating batch samplesthienqo/ios-skills
6bf8b62
Canonical home
since May 23, 2026
Also appears in
on Oct 29, 2026
since May 22, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.