Open Document from Files App

What particular configuration will allow a document based app (DocumentGroup) to open the application into the selected document when the document is touched in Files.app.

The sample code doesn't show this behaviour and instead will open the app but will not open the selected document. This also is the behaviour with the Xcode document based app template.

Using LSSupportsOpeningDocumentsInPlace = YES in the plist does not make any difference.

.onOpenURL is not a modifier on Scene only View and if the app is opened from cold the document view will not exist. In any case I would expect the DocumentGroup to open the document directly with no further intervention.

What additional magic do I need to get a document to open directly from Files.app (or Messages) . For example Swift Playgrounds shows the correct behaviour, opening the selected project directly.

@lizardx I believe your question was answered in a different post. Please see https://developer.apple.com/forums/thread/743967

Let me know if you have any further questions.

The linked answer isn't quite up to date and doesnt connect to a SwiftUI DocumentGroup

  1. Add a UIApplicationDelegate via @UIApplicationDelegateAdaptor
  2. Programmatically add a UISceneDelegate in the UIApplicationDelegate in
func application(
        _ application: UIApplication,
        configurationForConnecting connectingSceneSession: UISceneSession,
        options: UIScene.ConnectionOptions
    ) -> UISceneConfiguration {
        let sceneConfig: UISceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
        sceneConfig.delegateClass = MySceneDelegate.self
        return sceneConfig
    }
  1. This is where it differs from the linked answer. In the UISceneDelegate implement
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let url = URLContexts.first?.url {
            // How to get `DocumentGroup` to open url in its scene context ???
        }
    }

Where you could use MyUIDocument().open() in a UIKit context, FileDocument / ReferenceFileDocument doesn't have a corresponding open method.

Thanks

Open Document from Files App
 
 
Q