UIImageWriteToSavedPhotosAlbum(newImage,  self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)

使用此方法,我可以在相册中保存图像,但不能限制在相册中再次保存相同的照片

最佳答案

您可以检查在该路径(文档目录)中是否存在同名文件。

    let fileManager = FileManager.default
    var paths = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString)
    paths = paths.appending("nameOfYourFile") as (NSString)
    if !fileManager.fileExists(atPath: paths as String){
          //no such file exist at this path
          UIImageWriteToSavedPhotosAlbum(newImage,  self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
    }

关于ios - 如何限制将同一张照片再次添加到iOS的自定义相册中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47506391/

10-09 09:37