Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Create live photo throw Optional(Error Domain=PHPhotosErrorDomain Code=-1 "(null)")

I want to create a Live Photo. The project includes a .jpg image and a .mov video (2 seconds). I am sure they are correct.

Two permissions in xcode have been added: Privacy - Photo Library Usage Description Privacy - Photo Library Additions Usage Description Simulate: iphone 16, ios 18.3

The codes in ContentView.swift :

private func saveLivePhoto(imageURL: URL, videoURL: URL, completion: @escaping (Bool, Error?) -> Void) {

        PHPhotoLibrary.shared().performChanges {
            let creationRequest = PHAssetCreationRequest.forAsset()

            let options = PHAssetResourceCreationOptions()

            options.shouldMoveFile = false

            creationRequest.addResource(with: .photo, fileURL: imageURL, options: options)

            creationRequest.addResource(with: .pairedVideo, fileURL: videoURL, options: options)
        } completionHandler: { success, error in
            DispatchQueue.main.async {
                print(error)
                completion(success, error)
            }
        }
    }
       guard let imageURL = Bundle.main.url(forResource: "livephoto", withExtension: "jpeg"),
                      let videoURL = Bundle.main.url(forResource: "livephoto", withExtension: "mov") else {
                    showAlertMessage(title: "error", message: "cant find Live Photo ")
                    return
                }
                print("imageURL: \(imageURL)")
                print("videoURL: \(videoURL)")

                saveLivePhoto(imageURL: imageURL, videoURL: videoURL) { success, error in

                    if success {

                  xxxxx

                    } else {

                     xxxxx

                    }

                }

Really need help, thanks

I had this issues too, and try UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path), is also fail

Create live photo throw Optional(Error Domain=PHPhotosErrorDomain Code=-1 "(null)")
 
 
Q