Open My application from my keyboard extension in swift 3.0

I am trying to open from my keyboard extension. I am having custom keyboard and I have add that keyboard from setting. On my custom keyboard there is one button “Show More”, and I want to open my app on this button click.


So I have tried following code :


let context = NSExtensionContext()
context.open(url! as URL, completionHandler: nil)
var responder = self as UIResponder?
while (responder != nil) {
    if responder?.responds(to: Selector("openURL:")) == true { 
        responder?.perform(Selector("openURL:"), with: url) 
    }
    responder = responder!.next 
}

It is working successfully, but as we know in swift

Selector("method_name:")
is deprecated and use
#selector(classname.methodname(_:))
instead so it is giving warning. And I want to solve that warning. So I have tried as Xcode automatically suggested :


if responder?.responds(to: #selector(UIApplication.openURL(_:))) == true {
    responder?.perform(#selector(UIApplication.openURL(_:)), with: url)
}

Also tried :


if responder?.responds(to: #selector(NSExtensionContext.open(_:))) == true {
    responder?.perform(#selector(NSExtensionContext.open(_:)), with: url)
}


I have also tried others possible ways, but no luck. If anyone know how to do, please let me know.

I referred this link, Julio Bailon’s answer : openURL not work in Action Extension

Answered by DTS Engineer in 188516022

I want to be very clear: what you’re doing here is very much unsupported. Two points:

  • The

    open(_:completionHandler:)
    on NSExtensionContext is specifically documented for use on Today widgets only.
  • Trying to get around this by walking up the responder chain looking for and calling methods by their selector is not allowed.

While I realise that Apple can be rather opaque at times, the intent here is very clear: if we wanted

open(_:completionHandler:)
to work in arbitrary extensions, we would not gone out of our way to restrict it.

If you’d like your keyboard extension to be able to open your app, you should file an enhancement request for a supported way to do that. Personally, I think that’s a reasonable request, but I don’t get to make the call.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

I want to be very clear: what you’re doing here is very much unsupported. Two points:

  • The

    open(_:completionHandler:)
    on NSExtensionContext is specifically documented for use on Today widgets only.
  • Trying to get around this by walking up the responder chain looking for and calling methods by their selector is not allowed.

While I realise that Apple can be rather opaque at times, the intent here is very clear: if we wanted

open(_:completionHandler:)
to work in arbitrary extensions, we would not gone out of our way to restrict it.

If you’d like your keyboard extension to be able to open your app, you should file an enhancement request for a supported way to do that. Personally, I think that’s a reasonable request, but I don’t get to make the call.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi, eskimo

I have raised request for above problem, number is here : 28930966
Thanks for reply. 🙂

4 years later, no implementation done :). I'm trying to do the same approach for opening the container app of my share extension, I just don't get it why it's forbidden to use the open(_:completionHandler:) API...don't want to do any fancy stuff, just open the container app so that the user logs in before performing any actions from share extension.

Any update about this :) ?

Open My application from my keyboard extension in swift 3.0
 
 
Q