39 lines
1.1 KiB
Swift
39 lines
1.1 KiB
Swift
import Combine
|
|
import Foundation
|
|
import Photos
|
|
|
|
@MainActor
|
|
final class FileStore: ObservableObject {
|
|
@Published var cameraAccessGranted = false
|
|
@Published var galleryAccessGranted = false
|
|
|
|
private let client: Client
|
|
private let roster: Roster
|
|
|
|
init(roster: Roster, client: Client) {
|
|
self.client = client
|
|
self.roster = roster
|
|
}
|
|
}
|
|
|
|
extension FileStore {
|
|
func checkCameraAuthorization() async {
|
|
let status = AVCaptureDevice.authorizationStatus(for: .video)
|
|
var isAuthorized = status == .authorized
|
|
if status == .notDetermined {
|
|
isAuthorized = await AVCaptureDevice.requestAccess(for: .video)
|
|
}
|
|
cameraAccessGranted = isAuthorized
|
|
}
|
|
|
|
func checkGalleryAuthorization() async {
|
|
let status = PHPhotoLibrary.authorizationStatus()
|
|
var isAuthorized = status == .authorized
|
|
if status == .notDetermined {
|
|
let req = await PHPhotoLibrary.requestAuthorization(for: .readWrite)
|
|
isAuthorized = (req == .authorized) || (req == .limited)
|
|
}
|
|
galleryAccessGranted = isAuthorized
|
|
}
|
|
}
|