最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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. I can save each image and video, but save live photo always throw error.

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

These are codes in 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

                    }

                }


发布评论

评论列表(0)

  1. 暂无评论