iOS Share Extension vs Container App confusion

104 views Asked by At

I would like to provide for the common use-case of "Sharing" media (photos/video/audio) from a host app such as the iOS Photo gallery, with my app for further editing and subsequent sharing.

This functionality is pretty ubiquitous, per TikTok, CapCut et al.

In researching how to achieve this I've found conflicting opinions on launching/foregrounding a Container App by way of Share Extension invocation from a Host App. The majority of comments indicate this is not possible nor allowed. A minority state that they have it working, in comments as recent as Oct 2023.

https://stackoverflow.com/a/27517554

Share Extension conceptually seems like the natural choice, though "Today" by way of Widget Extension is the only extension that supports openURL.

Can anyone speak to how they achieve this on iOS 15 and later please?

So far I have found the following to be true: Creating a myApp:// via the Container apps plist and URL Schemes works very nicely - as in one can then enter "myApp://" into a Safari Browser and open their app.

App Groups provide an very convenient way to share data such as photo/video/audio media between app extensions and the Container app.

Share Extension plist have a convenient NSExtensionActivationRule mechanism for defining what the Containing app, by way of the Share Extension, will respond to. There's even a default of TRUEPREDICATE to easily test your app before locking down the flow to guide the user.

The stumbling block is purely the opening of the Container app. I have attempted to provide openURL in a Share Extension at the bottom of the UIViewController derived class like this:

    @objc func openURL(_ url: URL) -> Bool {
        var responder: UIResponder? = self
        while responder != nil {
            if let application = responder as? UIApplication {
                return application.perform(#selector(openURL(_:)), with: url) != nil
            }
            responder = responder?.next
        }
        return false
    }

This does indeed allow the functionality to work when the app is deployed to a device via physical connection and Xcode. However the functionality doesn't work when the app is deployed via TestFlight.

Any thoughts, pointers or advice on this would be beyond awesome! Many thanks :)

0

There are 0 answers