2

Is there any way to call container app method from extension keyboard?

I tried by using following NSNotificationCenter, But still its not working.

I have added NSNotificationCenter and method into my main container app.

NSNotificationCenter.defaultCenter().addObserver(
        self,
        selector: #selector(method),
        name: "methodClicked",
        object: nil)

func method(){
    //doing stuff
}

and in my app extension keyboard I'm checking if container app is currently visible then post that notification NSNotificationCenter.defaultCenter().postNotificationName("methodClicked", object: nil)

Please post answer in Objective-c or Swift if anyone know proper way to do it. Thanks in advance.

Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
  • Check this answer. You can't send notification to container app http://stackoverflow.com/questions/35411165/how-to-add-custom-notification-in-ios-custom-keyboard/35428839#35428839 – kb920 Jul 30 '16 at 11:12
  • @kb920 Yes this i know, we can share data through App Group. But actually my requirement is if I click on specific key from keyboard extension then I want to show UIAlertView into my container app. – Sunil Targe Jul 31 '16 at 14:57
  • @SunilTarge Did you got any solution? – Parth Patel Aug 26 '19 at 11:33
  • @ParthPatel I guess the solution is only we can share data through App Group. Answer this question, If you could find any other precise way to do that. thx – Sunil Targe Aug 26 '19 at 13:17

1 Answers1

0

I tried to do the same thing and realized (for now) that the only way to make an extension call a function on it's containing app is via remote server. that means when an event on the extension occur you can make a call to your remote server that will notify your app (using notification).

Probably an overkill but it should work.

ZygD
  • 22,092
  • 39
  • 79
  • 102
ygam
  • 101
  • 2