0

Friends

I have generated a PDF document that I wish to make available to the Files app

This is my code that works well, in that it puts up the dialogue from which I can select "Save to files". (pdfURLis the URL for the PDF document saved in the bundle. I can pass the data directly but it means I cannot programmatically set the file name)

        Button("Share app") {
            self.isSharePresented = true
        }
        .sheet(isPresented: $isSharePresented, onDismiss: {
            print("Dismiss")
        }, content: {
            PDFSaveController(activityItems: [pdfURL])
        })

But there is no directory for my App.

The user can create it (there is an option to create a directory), but my users will never see that and it will trigger endless angst.

I need to create the directory in the app.

I have followed https://stackoverflow.com/a/61631421/16675319 but the answer there is incorrect.

I have set the "Application supports iTunes file sharing" (Peculiar)

I use:

        let documentDirectoryURLs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        let documentDirectoryURL = documentDirectoryURLs[0]
        let directoryURL = documentDirectoryURL.appendingPathComponent("TestPDF_Shared", isDirectory: true)
        if !FileManager.default.fileExists(atPath: directoryURL.path) {
            do {
                try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
                return directoryURL
            } catch {
                print(error.localizedDescription)
                assert(false)
            }

which creates a directory, but it is not visible in the files app.

There are other directories visible in the Files app from other applications that I have installed but I did not create those directories as an app user, the apps created them on installation (I assume).

I am using: iOS 15.2.1 Xcode Version 13.2.1 Swift

Wrog
  • 21
  • 5
  • Not near my laptop but something like you need to add Cloud Documents to your entitlements. You’ll then get a dedicated app folder in Files. .documentDirectory should resolve to that folder automagically. The iTunes file sharing thing is well old. – Warren Burton Jan 18 '22 at 22:31
  • @WarrenBurton ITunes file sharing allows you to share your documents directory files with the finder nowadays. There is no iTunes anymore. To expose your files to the Files App check the duplicate link. – Leo Dabus Jan 19 '22 at 01:05

0 Answers0