【问题标题】:PHAsset copy from one album to anotherPHAsset 从一张专辑复制到另一张专辑
【发布时间】:2020-09-23 17:30:19
【问题描述】:

我想将资产从一个相册复制到另一个相册,而不要求提供 imageData 或 videoData,也就是说,只需将资产从一个相册复制到另一个相册

我在做什么

let asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetLocalIdentifier], options: .none).firstObject
PHPhotoLibrary.shared().performChanges({
    guard let albumChangeRequest = PHAssetCollectionChangeRequest(for: album) else { return }
    albumChangeRequest?.addAssets([asset] as NSFastEnumeration)
})

相册是我的自定义相册

我崩溃了

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectID]: unrecognized selector sent to instance 0x600002339340'

ofc 资产存在,专辑存在,如果我将视频保存到文件并使用 creationRequestForAssetFromVideo...

我通过 creationRequestForAssetFromVideo 保存没有问题,但为此我需要先保存此视频,并且我想复制用户选择的内容而不等待保存视频,这甚至可能吗?

【问题讨论】:

    标签: ios swift photo


    【解决方案1】:

    我找到路了)

    视频

    PHImageManager.default().requestAVAsset(forVideo: asset, options: PHVideoRequestOptions()) { (avAsset, _, _) in
        if let assetURL = avAsset as? AVURLAsset {
             _url = assetURL.url
    ....
    

    图片

    asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (contentEditingInput, _) in
        if let url = contentEditingInput?.fullSizeImageURL {
             _url = url
    ....
    

    现在是图片

    PHAssetChangeRequest.creationRequestForAssetFromImage
    

    或用于视频

    PHAssetChangeRequest.creationRequestForAssetFromVideo
    

    解释: 我们不能直接复制资产,但是我们可以从系统中的资产中获取路径,并使用它来复制到我们的相册中

    快乐编码 ;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-21
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多