How to provide iOS' Recents popover in own app, like Files.app has

Hi all,


I'm wondering how to implement the Recents popover, like Files.app and other apps, like Ulysses, offer, in my own app (see screenshot here)


I tried adding LSSupportsOpeningDocumentsInPlace, UIFileSharingEnabled and UISupportsDocumentBrowser (all set to YES) to Info.plist, to no avail - the popup doesn't come up when long-pressing my app's icon.


Thank you for any help,


Kind regards,

- Matt

Replies

In addition to including the keys you mentioned, I assume you also include the document types your app supports in the Info.plist (with CFBundleDocumentTypes and UTExportedTypeDeclarations).


Next, you must use UIDocument for your files. Here is an example:

final class CustomDoc: UIDocument {

    override func contents(forType typeName: String) throws -> Any {
        return "This is a test".data(using: .utf8)!
    }

    override func load(fromContents contents: Any, ofType typeName: String?) throws {

    }
}

    func saveTestDocument() {
        let localDocs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        try? FileManager.default.createDirectory(at: localDocs, withIntermediateDirectories: true, attributes: nil)
        let test = localDocs.appendingPathComponent("Test").appendingPathExtension("testfile")
        let doc = CustomDoc(fileURL: test)
        doc.save(to: doc.fileURL, for: .forCreating) { completion in
            print("completion: \(completion)")
        }
    }


I was able to get the recent files popover to work by including the proper Info.plist keys and using the code above.