skip to Main Content

I’m trying to show my data in my app in the Files app on my iPhone
I searched a lot and did everything right, I don’t know where the error is

func fileManger(nameFolder: String) {

    let manager = FileManager.default
    let DecomentFolder = manager.urls(for: .documentDirectory, in: .userDomainMask).last
    let Folder = DecomentFolder?.appendingPathComponent("(nameFolder)")

    do {
        try manager.createDirectory(at: Folder!, withIntermediateDirectories: true, attributes: [:])
    } catch let error {
        print(error.localizedDescription)
    }
}

Also here I am sending the value to be a folder

@objc func alertNewFolder () {
    let alert = UIAlertController(title: "Create an album", message: "", preferredStyle: .alert)
    alert.addTextField(configurationHandler: nil)
    alert.textFields![0].placeholder = "name album"
    alert.textFields![0].textAlignment = .right
    alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "save", style: .default, handler: { ـ in
        if let textFileds = alert.textFields {
            let links = textFileds[0].text
            self.arrS1.append(addCatogrey(nameCatog: links!, imageSection: UIImage(named: "folder")))
// Here Send FileManager
            helperCoding().fileManger(nameFolder: links!)
            self.collection.reloadData()
        }
    }))
    self.present(alert, animated: true, completion: nil)
}

In the Simulators it saved in the Documents folder here correctly

/Users/badrshammry/Library/Developer/CoreSimulator/Devices/7986A27F-7026-45E1-9073-78CCD6A9B90A/data/Containers/Data/Application/3173C4DC-BCDE-41B9-89E1-6E8D9B52EF25/Documents

3

Answers


  1. If you would like to expose your App document files inside Apple’s Files App you need to include the "Supports Document Browser" key in your info plist file and set it to YES:

    enter image description here

    Login or Signup to reply.
  2. To set Supports Document Browser has to be set in Custom iOS Target Propertiesin the info tab

    info.plist is no more from Xcode 13

    Anyhow, it does not work. The files App will not find files in the your app’s bundle. They need to be "shared" (In SwiftUI use UIViewControllerRepresentable)

    But your App will not have a directory in the file structure visible to the Files App. Adding that folder is still a mystery

    See: How can folders visible to FIles app be created by App programatically

    Login or Signup to reply.
  3. Add these two keys to ‘info.plist’ –

    ...
    <key>UIFileSharingEnabled</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>
    ...
    

    After this, files saved in ‘.documentDirectory’ will appear in ‘Files App’ inside a folder with your app name.

    If editing ‘info.plist’ in Xcode then add below keys –

    Application supports iTunes file sharing = YES
    Supports opening documents in place = YES
    

    info.plist

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search