Save files in application folder

When the app saves the photos, it will be shown in the Photos app. But I want to keep the photos inside the app folder and other apps won't be able to access it.

I am getting the path to save the files as shown below:

let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)

      

How can i do this?

Someone told me about using secure storage. Could this be my decision?

+3


source to share


1 answer


Save the image in your application's document folder like so:

func saveImageDocumentDirectory(image: UIImage, name:String){
    let paths = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(name)
    let imageData = UIImageJPEGRepresentation(image, 0.5)
    FileManager.default.createFile(atPath: paths as String, contents: imageData, attributes: nil)
}

      



There is no reason to use secure storage (unless you also want to protect data from hacking, etc.), since the application document folder is only accessible to your application.

Also, have a look at this blog: https://iosdevcenters.blogspot.com/2016/04/save-and-get-image-from-document.html

+1


source







All Articles