【问题标题】:How to move video file to a specific album in Photos?如何将视频文件移动到照片中的特定相册?
【发布时间】:2018-02-20 11:59:27
【问题描述】:

我可以将视频文件移至照片的根目录,但我想将其移至特定相册(使用localIdentifier

将视频文件移动到照片根目录的功能(需要对其进行编辑以移动到特定的照片相册-localIdentifier)

PHPhotoLibrary.shared().performChanges({
                print("performChanges")
                let options = PHAssetResourceCreationOptions()
                options.shouldMoveFile = true

                let creationRequest = PHAssetCreationRequest.forAsset()

                creationRequest.addResource(with: .video, fileURL: self._VideoFileURL, options: options)
            }, completionHandler: { success, error in
                if !success {
                    print("Could not save movie to photo library: \(String(describing: error))")
                } else {
                    print("Saved movie to photo library")
                }
            }

【问题讨论】:

标签: ios swift


【解决方案1】:

这是我用来检查文件是否已经存在的方法。

 static func isAlreadyExists(fileName:String) -> Bool {
    let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let filePath = documentsDirectory.appendingPathComponent(Constants.AppName).appendingPathComponent(fileName)

    if (FileManager.default.fileExists(atPath: filePath.path)){
        return true
    }else{
        return false
    }

}

这是将文件保存到特定文件夹的代码

  static func createDirectory() -> URL {
    let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let DocumentsDirectory = documentsDirectory.appendingPathComponent(Constants.AppName)

    if !(FileManager.default.fileExists(atPath: DocumentsDirectory.path)){
        do {
            try FileManager.default.createDirectory(atPath: DocumentsDirectory.path, withIntermediateDirectories: true, attributes: nil)
        } catch let error as NSError {
            print("? Error creating directory: \(error.localizedDescription)")
        }
    }
    return DocumentsDirectory

}

希望它对你有用。

【讨论】:

  • 如何将它用于相册中的相册? p.s.这只是我问题的一部分,我还想了解如何将文件移动到照片中的特定相册(我的问题的主要部分)
  • 附注我说的是照片框架 - developer.apple.com/documentation/photos
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 2011-07-27
  • 1970-01-01
  • 2013-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多