---
title: SRSensorReader
framework: sensorkit
role: symbol
role_heading: Class
path: sensorkit/srsensorreader
---

# SRSensorReader

An object that establishes user authorization and records data for a particular sensor.

## Declaration

```swift
class SRSensorReader
```

## Overview

Overview To acquire data from a particular sensor using a reader, an app creates an instance of this class using init(sensor:) and passes in one sensor from the available options in Sensors. A reader is a data stream for a particular sensor that the user must authorize before use. When an app calls requestAuthorization(sensors:completion:), the OS prompts the user for approval to use the particular sensor and determines the app’s authorization according to the user’s answer. The framework notifies the delegate with the  sensorReader(_:didChange:) callback if the authorization status changes as a result of the requestAuthorization(sensors:completion:) call. When a reader’s authorizationStatus is SRAuthorizationStatus.authorized, an app starts collecting sensor data by beginning recording. When an app calls startRecording(), the framework starts the reader’s sensor if it isn’t already running because of a request from another app or a system process. An app has access to 7 days of prior recorded data for an active sensor. When an app calls stopRecording(), the app relinquishes stakeholdership in the sensor. When a sensor has no app or system stakeholders, the framework deactivates the sensor and, thereby, stops recording data. To fetch a sensor’s data, pass a request object to the fetch(_:) function. SRFetchRequest specifies a time range that defines the age of the data, and a device, such as a phone or a watch, from which to collect the data. Use fetchDevices() to list the available devices, and use the time convenience-functions in Defining the Time Range to specify the time range. If the fetch query succeeds, the framework notifies the delegate with sensorReader(_:didCompleteFetch:). The delegate receives sensor data in the form of samples from sensorReader(_:fetching:didFetchResult:). A fetch result’s sample type is different depending on the particular sensor for the reader. For a mapping of sensors to their samples, see Sample types.

## Topics

### Checking user authorization

- [authorizationStatus](sensorkit/srsensorreader/authorizationstatus.md)
- [requestAuthorization(sensors:completion:)](sensorkit/srsensorreader/requestauthorization(sensors:completion:).md)
- [SRAuthorizationStatus](sensorkit/srauthorizationstatus.md)

### Creating a sensor reader

- [init(sensor:)](sensorkit/srsensorreader/init(sensor:).md)
- [SRSensor](sensorkit/srsensor.md)
- [sensor](sensorkit/srsensorreader/sensor.md)

### Recording sensor data

- [startRecording()](sensorkit/srsensorreader/startrecording().md)
- [stopRecording()](sensorkit/srsensorreader/stoprecording().md)

### Reading recorded data

- [fetch(_:)](sensorkit/srsensorreader/fetch(_:).md)
- [fetchDevices()](sensorkit/srsensorreader/fetchdevices().md)
- [SRDevice](sensorkit/srdevice.md)

### Responding to sensor events

- [delegate](sensorkit/srsensorreader/delegate.md)
- [SRSensorReaderDelegate](sensorkit/srsensorreaderdelegate.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Setup

- [Configuring your project for sensor reading](sensorkit/configuring-your-project-for-sensor-reading.md)
