I tried a different approach to adding the images to the Photo Library, using:
func createStillAssetOnAlbum(asset: URL, album: PHAssetCollection) {
let photoURL = asset
PHPhotoLibrary.shared().performChanges ({
let creationRequest = PHAssetCreationRequest.forAsset()
let placeHolderAsset = creationRequest.placeholderForCreatedAsset
creationRequest.addResource(with: .photo, fileURL: photoURL, 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): \(e)")
self.nonImportedImageCount += 1
}
})
}
This seems to work as I would expect.