requestAuthorization(sensors:completion:)
Requests user permission to read one or more sensors.
Declaration
class func requestAuthorization(sensors: Set<SRSensor>, completion: @escaping @Sendable ((any Error)?) -> Void)class func requestAuthorization(sensors: Set<SRSensor>) async throwsParameters
- sensors:
One or more sensors your app requests.
- completion:
A closure to run after the framework determines user authorization.
Discussion
Call this function for sensors in which authorizationStatus is SRAuthorizationStatus.notDetermined to display a prompt that requests user authorization. When the prompt dismisses, the framework calls the completion closure. Your delegate needs to wait for a call to sensorReader(_:didChange:) to determine whether the user approves sensor access.
If you pass a sensor into this function for which the user already answered the in-app prompt, the framework cancels the prompt with SRError.Code.promptDeclined. When the user has already answered the prompt for a particular sensor, its authorizationStatus is SRAuthorizationStatus.authorized or SRAuthorizationStatus.denied. The user may change the authorization status for a sensor in Settings > Privacy > Research Sensor & Usage Data.
For more information about the authorization workflow, see Configuring your project for sensor reading.