小编xlo*_*gic的帖子

检查照片中是否存在图像

我有一张由远程服务器管理的图像专辑.我想为用户提供下载相册的选项,并将其存储到照片中的自定义相册中.但由于专辑是动态的(照片被添加到其中),用户可以多次下载.我不想多次下载相同的图片,只有新的.

当我将图像存储在Photo应用程序中时,是否可以关联一些元数据(唯一ID)?然后检查该图像是否已存在?

我正在使用照片框架来创建自定义相册并保存照片.

编辑:这是我创建自定义相册和保存照片的代码

/** Returns the first album from the photos app with the specified name. */
static func getAlbumWithName(name: String, completion: (album: PHAssetCollection?) -> Void) {

    let fetchOptions = PHFetchOptions()
    fetchOptions.predicate = NSPredicate(format: "localizedTitle = %@", name)
    let fetchResult = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.Album, subtype: PHAssetCollectionSubtype.Any, options: fetchOptions)

    if fetchResult.count > 0 {

        guard let album = fetchResult.firstObject as? PHAssetCollection else {return}
        completion(album: album)

    } else {

        PHPhotoLibrary.sharedPhotoLibrary().performChanges({

            PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(name)

            }, completionHandler: { (result, error) in

                if result {

                    FileUtils.getAlbumWithName(name, completion: completion) …
Run Code Online (Sandbox Code Playgroud)

ios swift

6
推荐指数
1
解决办法
2074
查看次数

标签 统计

ios ×1

swift ×1