简体   繁体   中英

How to restrict same photo to be added again in custom album in iOS?

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

使用这种方法,我可以将图像保存在相册中,但不能限制再次将同一张照片保存在相册中

You can check whether file of same name exist at that path (Document-directory).

    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) 
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM