UIDocumentPickerViewController works on iOS, not on Mac Catalyst??

The code below works fine on an iPad or iPhone -- saveDocument() writes to /Users/me/Library/Containers/My-App/Data/Documents, and openDocument() shows me the content of that folder. Beautiful.

On macOS, openDocument() shows the Documents folder at the root level of iCloud Drive, not the sandboxed version, which is local to my computer

It's like the documentPickerVC.directoryURL is being ignored. Why?? What am I doing wrong.

If it helps, the documentURL looks like this:

file:///Users/me/Library/Containers/org.me.My-App/Data/Documents/

Any help would be really, really appreciated!


Code Block  
func saveDocument(){
        let encoder = JSONEncoder()
        encoder.outputFormatting = .prettyPrinted
        do {
            let puzzleData = try? encoder.encode(puzzle)
print("Saving: \(documentURL)")
            let saveableURL = documentURL!.appendingPathComponent("\( .puzzle.date)")
            try puzzleData!.write(to: saveableURL)
        } catch {
            displayError(title: "Error while saving document", message: "There was an error: \(error)")
        }
    }
        // when the user taps on the Open button
    @objc func openDocument(){
        documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: [UTType("public.item")!, UTType("public.data")!], asCopy: true )
        documentPickerVC.delegate = self
        documentPickerVC.modalPresentationStyle = .formSheet
        documentPickerVC.directoryURL = documentURL
        self.present(documentPickerVC, animated: true)
    }


Answered by mprogers in 679542022

The documentation now states that this property is ignored in Mac Catalyst (I'm not sure if that was there when I originally posted the question).

Accepted Answer

The documentation now states that this property is ignored in Mac Catalyst (I'm not sure if that was there when I originally posted the question).

UIDocumentPickerViewController works on iOS, not on Mac Catalyst??
 
 
Q