another.im-ios/ConversationsClassic/AppData/Store/FileStore.swift

39 lines
1.1 KiB
Swift
Raw Normal View History

2024-08-17 12:11:11 +00:00
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
}
}