Search code examples
iosobjective-cswiftwatchkit

How do I communicate between GlanceController and InterfaceController in Watchkit?


According to the Apple documentation for Watchkit one uses willActivate to update a glance scene with the most up to date information. What is the recommended way to access that "most up to date" information, or in other-words how do I communicate between the GlanceController and the InterfaceController? I am currently using Swift but an answer in Obj-C is fine too. I cannot seem to find this in the documentation.


Solution

  • Do you mean handoff from a Glance Controller to an Interface Controller?

    Coordinating Handoff
    If so you'll want to check out Coordinating Handoff Activity

    Implement func handleUserActivity(_ userInfo: [NSObject : AnyObject]!) on your Initial Interface Controller.

    Then a userInfo dictionary to updateUserActivity:userInfo: method and provide a context to transition from Glance -> Watch App.

    Sharing Data
    To share the most 'up-to-date' data with your Glance you should be architecting your Watch Extension/iOS Application to be regularly persisting data into a Shared App Container that both your iOS app and Extension can access. When your Glance opens it would simply fetch its data (expected to be the latest) from the shared container and display it.