[英]How to restrict same photo to be added again in custom album in iOS?
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.