【问题标题】:Add assets to an iCloud shared photo album programmatically以编程方式将资产添加到 iCloud 共享相册
【发布时间】:2020-03-23 13:12:09
【问题描述】:

使用 PhotoKit 将照片添加到共享的 iCloud 相册是否有任何限制?虽然我可以将新照片添加到作为常规相册的 AssetCollection,但如果 AssetCollection 代表 iCloud 共享相册,它根本不起作用。我是否还需要添加不同类型的 PHAsset?

如果我将fetchAssetCollections 调用更改为使用.albumRegular 而不是.albumCloudShared,则下面的代码有效。否则我会得到一个错误:

The operation couldn't be completed. (PHPhotosErrorDomain error -1.)

let sharedAlbums = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumCloudShared, options: nil)

let target = sharedAlbums.firstObject

PHPhotoLibrary.shared().performChanges({
    let assetChangeRequest = PHAssetChangeRequest.creationRequestForAsset(from: wantedimage)
    let assetPlaceHolder = assetChangeRequest.placeholderForCreatedAsset
    let albumChangeRequestShared = PHAssetCollectionChangeRequest(for: target!)
    let enumeration: NSArray = [assetPlaceHolder!]
    albumChangeRequestShared!.addAssets(enumeration)
}, completionHandler: { result, error in 
    print(result)
    print(error)
    print(error?.localizedDescription)
})


【问题讨论】:

    标签: swift icloud photokit


    【解决方案1】:

    是的,您不能将图像添加到 iCloud 共享相册。

    在执行更改请求之前,您应该在 PHAssetCollection 上调用 canPerform(_:)

    如果您在 PHAssetCollectionSubtypealbumCloudShared 上调用 canPerform(_:),它将返回 false。

    例如:

        print(collection.canPerform(.createContent)) //false
         
        print(collection.canPerform(.addContent)) //false 
    

    我遇到了同样的问题,并通过反馈应用提交了功能请求。

    【讨论】:

    • 您是否收到过关于您的功能请求的回复?
    • 很遗憾,我没有收到任何回复。
    猜你喜欢
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 2011-01-18
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多