Reputation: 151
I'm trying to add image assets to a Photo Library, using a PHAssetCreationRequest. I can add photos, videos and live photos but I'm also trying to include adjustment data (in the form of AAE files).
Here is my code (for adding still images):
func createStillAssetOnAlbum(photoAsset: URL, adjustmentAssets: [URL], album: PHAssetCollection) {
PHPhotoLibrary.shared().performChanges ({
let creationRequest = PHAssetCreationRequest.forAsset()
let placeHolderAsset = creationRequest.placeholderForCreatedAsset
creationRequest.addResource(with: .photo, fileURL: photoAsset, options: nil)
adjustmentAssets.forEach { adjustmentAsset in
creationRequest.addResource(with: .adjustmentData, fileURL: adjustmentAsset, options: nil)
}
guard let albumChangeRequest = PHAssetCollectionChangeRequest(for: album) else {
print("album change request has failed")
return
}
albumChangeRequest.addAssets([placeHolderAsset] as NSArray)
}, completionHandler: { success, error in
if success {
print("photo (and adjustments) saved successfully")
self.importCount += 1
}
else if let e = error {
print("error saving photo (and adjustment): \(photoAsset.lastPathComponent)")
self.nonImportedImageCount += 1
}
})
}
I'm using the method to add the assets by providing their URLs. First I add the .photo asset type, then any AAEs that are related to the photos, using the .adjustmentData asset type.
With this code any photos that do not have AAEs are imported but the code fails to import the photos that have AAE files.
Can anyone suggest what I might be doing wrong? I would appreciate any advice. Thanks very much
Upvotes: 0
Views: 397
Reputation: 16
Do you see any errors in the console log when trying this? Do you see the same failure if you use the data api as opposed to the url one? https://developer.apple.com/documentation/photokit/phassetcreationrequest/1622684-addresource
Upvotes: 0