diff --git a/Demo/Aespa-iOS/VideoContentViewModel.swift b/Demo/Aespa-iOS/VideoContentViewModel.swift index 7862117..2fcfb3b 100644 --- a/Demo/Aespa-iOS/VideoContentViewModel.swift +++ b/Demo/Aespa-iOS/VideoContentViewModel.swift @@ -31,7 +31,7 @@ class VideoContentViewModel: ObservableObject { @Published var photoFiles: [PhotoFile] = [] init() { - let option = AespaOption(albumName: "Aespa-Demo") + let option = AespaOption(albumName: "Aespa-Demo-App") self.aespaSession = Aespa.session(with: option) // Common setting diff --git a/Sources/Aespa/Processor/Asset/PhotoAssetAdditionProcessor.swift b/Sources/Aespa/Processor/Asset/PhotoAssetAdditionProcessor.swift index bf24d55..30d652d 100644 --- a/Sources/Aespa/Processor/Asset/PhotoAssetAdditionProcessor.swift +++ b/Sources/Aespa/Processor/Asset/PhotoAssetAdditionProcessor.swift @@ -26,10 +26,9 @@ struct PhotoAssetAdditionProcessor: AespaAssetProcessing { } try await add(imageData: imageData, to: assetCollection, photoLibrary) - Logger.log(message: "File is added to album") } - - /// Add the video to the app's album roll + + /// Add the photo to the app's album roll func add< T: AespaAssetLibraryRepresentable, U: AespaAssetCollectionRepresentable >( @@ -41,6 +40,20 @@ struct PhotoAssetAdditionProcessor: AespaAssetProcessing { // Request creating an asset from the image. let creationRequest = PHAssetCreationRequest.forAsset() creationRequest.addResource(with: .photo, data: imageData, options: nil) + + // Add the asset to the desired album. + guard + let placeholder = creationRequest.placeholderForCreatedAsset, + let albumChangeRequest = PHAssetCollectionChangeRequest(for: album.underlyingAssetCollection) + else { + Logger.log(error: AespaError.album(reason: .unabledToAccess)) + return + } + + let enumeration = NSArray(object: placeholder) + albumChangeRequest.addAssets(enumeration) + + Logger.log(message: "Photo is added to album") } } } diff --git a/Sources/Aespa/Processor/Asset/VideoAssetAdditionProcessor.swift b/Sources/Aespa/Processor/Asset/VideoAssetAdditionProcessor.swift index 8daab77..9290332 100644 --- a/Sources/Aespa/Processor/Asset/VideoAssetAdditionProcessor.swift +++ b/Sources/Aespa/Processor/Asset/VideoAssetAdditionProcessor.swift @@ -26,7 +26,6 @@ struct VideoAssetAdditionProcessor: AespaAssetProcessing { } try await add(video: filePath, to: assetCollection, photoLibrary) - Logger.log(message: "File is added to album") } /// Add the video to the app's album roll @@ -42,8 +41,7 @@ struct VideoAssetAdditionProcessor: AespaAssetProcessing { return try await photoLibrary.performChanges { guard - let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo( - atFileURL: path), + let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: path), let placeholder = assetChangeRequest.placeholderForCreatedAsset, let albumChangeRequest = PHAssetCollectionChangeRequest(for: album.underlyingAssetCollection) else { @@ -53,6 +51,8 @@ struct VideoAssetAdditionProcessor: AespaAssetProcessing { let enumeration = NSArray(object: placeholder) albumChangeRequest.addAssets(enumeration) + + Logger.log(message: "File is added to album") } } }