user2585453
user2585453

Reputation: 249

How to communicate between Widget and WatchOS2?

I have an app support widget and WatchOS, and it has a data store (core data). In the past I used app grouping to communicate among main app, widget and Watch app.

But the watch app is very slow after user upgraded to WatchOS 3.

Now I have rewrite the watch part to be native. It runs smoothly with communication via WatchConnectivity library between main app and WatchOS.

But I cannot find a way to communicate between widget and WatchOS. E.g. if some data get changed due to action by user in the widget, how can I update the data in the WatchOS?

I have tried the updateApplicationContext, but it report either "WCSession has not been activated" or watchApp not installed if the request is from widget.

Help needed! Thanks!

Upvotes: 1

Views: 165

Answers (1)

John Pollard
John Pollard

Reputation: 450

I'm pretty certain you can't talk directly from your Today widget to your watch app. Apple's architecture means the watch app can only talk to the associated iOS phone app, and in WatchOS2/3 the watch extension code now runs on the watch itself not the phone.

I'm sure you've thought of these already, but what I what I would do is some/all of the following:

  1. When the widget changes the data, write something to Core Data or User settings to say changes have been made (if this isn't obvious already)
  2. Get the phone app to do background pushes to the watch - either on a background refresh, or maybe setup a notification to wake up the phone app at regular intervals
  3. Get the watch app to pull in the latest data via the phone app when it is activated

Let us know if you find an good solution for this.

Upvotes: 1

Related Questions