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
I want to be very clear: what you’re doing here is very much unsupported. Two points:
The
on NSExtensionContext is specifically documented for use on Today widgets only.open(_:completionHandler:)
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"