arduino / Arduino-Science-Journal-iOS

Use the sensors in your mobile devices to perform science experiments. Science doesn’t just happen in the classroom or lab—tools like Science Journal let you see how the world works with just your phone.
http://arduino.cc/education
Apache License 2.0
22 stars 9 forks source link

Fix camera permission #49

Closed emiliopavia closed 3 years ago

emiliopavia commented 3 years ago

Checklist

Motivation and Context

The app asks for camera permission after starting a recording for the first time. As it's not the right time to do that I made a refactor to fix it.

Description

The current implementation asks for camera permission just to know if the camera access is available. I split the two use cases in CameraAccessHandler:

static var hasGrantedAccess: Bool

returns the state without asking for the permission the first time.

static func checkForPermission(requestCompletion: ((Bool) -> Void)? = nil)

checks the permission state and request for it if it's .notDetermined. The result is handled via a callback that can be asynchronous.

Then I modified all the points in the app where these APIs were used.