mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 11:00:50 +00:00
22 lines
674 B
Swift
22 lines
674 B
Swift
import AVFoundation
|
|
|
|
public enum CameraAuthorization {
|
|
public static func isAuthorized(for mediaType: AVMediaType) async -> Bool {
|
|
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
|
switch status {
|
|
case .authorized:
|
|
return true
|
|
case .notDetermined:
|
|
return await withCheckedContinuation(isolation: nil) { cont in
|
|
AVCaptureDevice.requestAccess(for: mediaType) { granted in
|
|
cont.resume(returning: granted)
|
|
}
|
|
}
|
|
case .denied, .restricted:
|
|
return false
|
|
@unknown default:
|
|
return false
|
|
}
|
|
}
|
|
}
|