20 lines
576 B
Swift
20 lines
576 B
Swift
|
|
import Foundation
|
||
|
|
import Photos
|
||
|
|
|
||
|
|
@MainActor
|
||
|
|
final class BackupViewModel: ObservableObject {
|
||
|
|
@Published var totalPhotoCount: Int = 0
|
||
|
|
@Published var photosAuthStatus: PHAuthorizationStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
|
||
|
|
|
||
|
|
private let photoService = PhotoLibraryService()
|
||
|
|
|
||
|
|
func loadPhotoCount(filter: BackupFilter) {
|
||
|
|
let assets = photoService.fetchAssets(filter: filter)
|
||
|
|
totalPhotoCount = assets.count
|
||
|
|
}
|
||
|
|
|
||
|
|
func requestPhotosAccess() async {
|
||
|
|
photosAuthStatus = await photoService.requestAuthorization()
|
||
|
|
}
|
||
|
|
}
|