Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save files inside app folder

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

I get the path to save files as below:

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

How can I do it?

Someone told me about using secure storage. Can it be my solution?

like image 814
A.bee Avatar asked Sep 14 '25 20:09

A.bee


1 Answers

Save an image to the App document folder like this:

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 a secure store (unless you also want to protect data from hacking etc), as the App document folder is only accessable to your App.

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

like image 51
thomas gotzsche Avatar answered Sep 16 '25 10:09

thomas gotzsche