Skip to content

Commit

Permalink
Merge pull request #19 from enebin/release/0.3.1
Browse files Browse the repository at this point in the history
release/0.3.1
  • Loading branch information
enebin authored Jul 5, 2023
2 parents 8de0f9b + 129603e commit ff14219
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Demo/Aespa-iOS/VideoContentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions Sources/Aespa/Processor/Asset/PhotoAssetAdditionProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
>(
Expand All @@ -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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -53,6 +51,8 @@ struct VideoAssetAdditionProcessor: AespaAssetProcessing {

let enumeration = NSArray(object: placeholder)
albumChangeRequest.addAssets(enumeration)

Logger.log(message: "File is added to album")
}
}
}

0 comments on commit ff14219

Please sign in to comment.