Share Extension to Open Containing App

Share Extension to open containing app

Currently there's no way to do this. A share extension cannot open the containing app.

The intended approach for share extensions is that they handle all of the necessary work themselves. Extensions can share code with their containing apps by using custom frameworks, so in most cases that's no problem.

If you want to make data available to your app, you can set up an app group so that you have a shared directory. The extension can write data there, and the app can read it. That won't happen until the next time the user launches the app, though.

Will Apple Reject If I open containing app from share extension?

Though there are loads of questions on how to open containing/parent app from share extension, none actually talk whether the proposed solution/hack will be approved by apple or not in detail.

One such example is

Share Extension to open containing app

suggests that Share extensions are not supposed to open the container app.

While browsing some time back, I rather found a very interesting thread discussing the same topic here

https://forums.developer.apple.com/thread/27295

The thread questions, whether the hack of traversing UIResponder chain to open the parent app using openURL will be allowed by apple or not? (Precisely the same idea shown in your posted link as well).

Though the thread again does not provide clear answer as, whether it will be approved by apple or not but points out a very valid concern and warning

The fact that +[UIApplication sharedApplication], and hence -openURL:, is not available to extensions should be an important hint here.Ignoring that restriction and looking up the symbols via the Objective-C runtime is not a good idea.

Clearly, thread suggests (implicitly, by not clearly stating the fact that apple will reject the app with such hack) that though apple will approve the app for now, it will only be a temporary solution.

Now this finally leads to the answer:

Answer:

In a recent apple event held @ Bangalore, I had an opportunity to meet the developers of extension team @ apple. I told them that I have been using the above mentioned hack to open the app from share extension will this be allowed by apple?

His answer:

`UIResponder`

is not a private entity, hence usage of UIResponder will not violate the private API usage condition hence apps which are using the above hacks are still being approved by apple. But the fact that, your code parses through the UIResponder chain to trigger the openURL is very costly and not suggested/preferred.As Apple seems to be aware of developer using it, they might start rejecting the app in future. (Must say, he wasn't sure of the last point, apple rejecting app in future hence highlighting might)

He also happened to mention about usage of WebView to open the app which developers used quite sometime back as well. Which is no longer working.

Conclusion:

Yes you can submit the app which opens the parent app from extension using above hack but being completely aware of the fact that this is only a temporary solution and apple expects you to write completely independent share extensions

Question is Answered for current iOS version of iOS11. The answer might lose its validity with future releases of iOS

Open the main app from a iOS Safari Share Extension

I found a solution here. I'm not sure if this is technically ok with Apple, but it works just as I need it to.

@objc func openURL(_ url: URL) {
return
}

func openContainerApp() {
var responder: UIResponder? = self as UIResponder
let selector = #selector(MyViewController.openURL(_:))

while responder != nil {
if responder!.responds(to: selector) && responder != self {
responder!.perform(selector, with: URL(string: "myapp://url")!)
return
}
responder = responder?.next
}
}

Create iOS share extension that opens my app

System doesn't technically opens your app when user taps on an icon of a ShareExtension. What ShareExtension is - a small binary that's separate from your container (main) iOS app.

Those apps, that appear in activity controller as share extensions, implement a special UI just for that share extension, instead of being opened when user taps on it.

You can implement a share extension that would store files to your main app documents dir or webserver or whatever.

You start by adding a target for the extension and then implement a view controller either from scratch or by inheriting from SLComposeServiceViewController

You can start at this wwdc video



Related Topics



Leave a reply



Submit