2 Replies
      Latest reply: Nov 3, 2016 4:28 AM by vimipatel RSS
      vimipatel Level 2 Level 2 (30 points)

        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

        • Re: Open My application from my keyboard extension in swift 3.0
          eskimo Apple Staff Apple Staff (6,665 points)

          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"