2

我想将PHAsset一张专辑从一张专辑移到另一张专辑。这是我正在做的事情:

func saveImage(image: UIImage, album: PhotoAlbum, completion: (PHFetchResult?)->()) {
        var placeholder: PHObjectPlaceholder?
        PHPhotoLibrary.sharedPhotoLibrary().performChanges({
            // Request creating an asset from the image
            let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
            // Request editing the album
            guard let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: album) else {
                assert(false, "Album change request failed")
                return
            }
            // Get a placeholder for the new asset and add it to the album editing request
            guard let photoPlaceholder = createAssetRequest.placeholderForCreatedAsset else {
                assert(false, "Placeholder is nil")
                return
            }
            placeholder = photoPlaceholder
            albumChangeRequest.addAssets([photoPlaceholder])
            }, completionHandler: { success, error in
                guard let placeholder = placeholder else {
                    assert(false, "Placeholder is nil")
                    completion(nil)
                    return
                }

            if success {
                completion(PHAsset.fetchAssetsWithLocalIdentifiers([placeholder.localIdentifier], options: nil))
            }
            else {
                print(error)
                completion(nil)
            }
    })
}

问题是它创建了一个副本到目的地而不是移动。最后,我最终在不同的专辑中获得了相同的图像。

4

0 回答 0