How can I respond to files from a Share Extension in an app using a SwiftUI 2.0 lifecycle?

382 views Asked by At

I'm building an app using the SwiftUI 2.0 lifecycle on iOS14.

I haven't used them before but I've added a Share Extension target to my project & have configured it to only open the specific types of files I want to be able to open in my app.

When opening the share sheet on my file type, my app shows as expected and my app is opened when tapping on it.

I'm now trying to work out how to handle those incoming files?

I've added an appDelegate adaptor to my App struct and know I can use:

 func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)

to handle Home Screen quick actions and:

func application(_ application: UIApplication, handlerFor intent: INIntent)

to handle Shortcut/Siri intents but I can't find an appropriate method for handling incoming files from the Share Extension.

I've also looked at the new onOpenUrl and onContinueUserActivity instance methods but no dice either.

It seems as thought in UIKit you have an extensionContext with inputItems in a ViewController but I can't find anything similar with SwiftUI.

Can anyone point me in the right direction please? Thank you!

Edit: It appears that I do get one URL from onOpenUrl from the incoming files. Haven't worked out multiple files yet.

0

There are 0 answers