Johnston
Johnston

Reputation: 20884

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.

Upvotes: 2

Views: 1709

Answers (3)

phillfarrugia
phillfarrugia

Reputation: 654

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.

Upvotes: 2

Cap
Cap

Reputation: 2044

You need to implement in your interface controller : - (void)handleUserActivity:(NSDictionary *)userInfo. And in the Glance Controller call updateUserActivity:userInfo: with the userInfos you want to pass to your interfaceController.

Upvotes: 2

Hieu Duc Pham
Hieu Duc Pham

Reputation: 1074

You can work in glance controller Like working in interface controller to get the "most up to date" information and save the result to NSUserdefault and after that you get back result from NSUserDefault in Interface Controller.

Upvotes: 1

Related Questions