Issue adding Apple ProRaw (DNG) files to Photos Library

I am using the code below to import images into a Photos Library. The code works for JPGs and HEICs but when it encounters Apple ProRaw (DNG) files it give the following error messages:

Error Domain=PHPhotosErrorDomain Code=3302
findWriterForTypeAndAlternateType:119: unsupported file format 'com.adobe.raw-image'

Here is the code:

func createPhotoOnAlbum(photo: UIImage, album: PHAssetCollection) {
        

            PHPhotoLibrary.shared().performChanges({
                    // Request creating an asset from the image
                    let createAssetRequest = PHAssetChangeRequest.creationRequestForAsset(from: photo)
                    // Request editing the album
                    guard let albumChangeRequest = PHAssetCollectionChangeRequest(for: album) else {
                        print("album change request has failed")
                        // Album change request has failed
                        return
                    }
                    // Get a placeholder for the new asset and add it to the album editing request
                    guard let photoPlaceholder = createAssetRequest.placeholderForCreatedAsset else {
                        // Photo Placeholder is nil
                        return
                    }
                    albumChangeRequest.addAssets([photoPlaceholder] as NSArray)
                }, completionHandler: { success, error in
                    if success {
                        // Saved successfully!
                        print("saved successfully")
                        self.importCount += 1
                    }
                    else if let e = error {
                        // Save photo failed with error
                        print("error saving: \(error)")
                    }
                    else {
                        print("error -> ")
                        // Save photo failed with no error
                    }
                })

These are definitely unedited ProRaw DNGs.

On a Mac they can be imported into a Photos Library using the "Import" menu command.

On an iPad they can be brought into the Photos Library by selecting them in the file system on the iPad, tapping Share, then tapping Save Images.

Thank you for any assistance with this.

Replies

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.